TimeValue.h fails to compile as C++26 with Clang 22

Aperta Adatta ai principianti
#8,992 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@reginaldalfret ci sta già lavorando.

Dal 9/10/2026.

  • #9021 di @reginaldalfret — aperta

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
92/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
compilers

Direzione di ricerca

Iniziare da include/llvm/Support/TimeValue.h, in particolare dal costruttore llvm::sys::TimeValue(double) e dall’espressione identificata alle righe 110-111. Riprodurre il problema con il comando C++26 clang++ fornito e verificare quindi che l’header e l’esempio di TimeValue fornito vengano compilati correttamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug needs-triage

Description

Building a C++26 consumer of DXC headers with Clang 22 fails in
include/llvm/Support/TimeValue.h.

The llvm::sys::TimeValue(double) constructor multiplies a double by the
unscoped TimeConversions enumerator NANOSECONDS_PER_SECOND:

nanos_ = static_cast<NanoSecondsType>(
    (new_time - static_cast<double>(integer_part)) *
    NANOSECONDS_PER_SECOND);

Arithmetic between a floating-point type and an enumeration was deprecated in
C++20 and removed from C++26 by P2864R2:

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2864r2.pdf

The same code builds in earlier C++ language modes. Adding an explicit
conversion for the enumerator resolves the C++26 failure without changing the
calculation.

The affected expression is also present on the current main branch:

https://github.com/microsoft/DirectXShaderCompiler/blob/main/include/llvm/Support/TimeValue.h#L110-L111

Steps to Reproduce

  1. Check out DXC tag upstream/v1.9.2607, commit
    0d3ee6b551b8fa768fbf825300ebab81047ef6a8.

  2. Configure the normal generated DXC include directory.

  3. Create a translation unit that includes the affected header:

#include "llvm/Support/TimeValue.h"

int main() {
  llvm::sys::TimeValue value(0.5);
  return value.nanoseconds() == 0;
}
  1. Compile it with Clang 22 in C++26 mode, supplying the DXC source and
    generated include directories:
clang++ \
  -std=c++26 \
  -stdlib=libc++ \
  -I/path/to/DirectXShaderCompiler/include \
  -I/path/to/dxc-build/include \
  -fsyntax-only \
  repro.cpp

The problem was originally encountered while compiling an application that
includes llvm/Support/FileSystem.h, which transitively includes
TimeValue.h.

Expected Behavior

DXC headers should compile successfully when included by a C++26 translation
unit.

Actual Behavior

Clang 22 reports:

include/llvm/Support/TimeValue.h:111:51: error: invalid arithmetic between
floating-point type 'double' and enumeration type
'llvm::sys::TimeValue::TimeConversions'

static_cast<double>(integer_part)) * NANOSECONDS_PER_SECOND );
                                     ^~~~~~~~~~~~~~~~~~~~~~

Proposed Fix

Explicitly convert the enumerator to double:

       nanos_ = static_cast<NanoSecondsType>( (new_time -
-               static_cast<double>(integer_part)) * NANOSECONDS_PER_SECOND );
+               static_cast<double>(integer_part)) *
+               static_cast<double>(NANOSECONDS_PER_SECOND) );

I verified that this change resolves the C++26 build failure.

Environment

  • DXC source version: upstream/v1.9.2607

  • DXC commit: 0d3ee6b551b8fa768fbf825300ebab81047ef6a8

  • Compiler:

    Ubuntu clang version 22.1.8 (++20260714014902+ca7933e47d3a-1~exp1~20260714135019.80)
    Target: x86_64-pc-linux-gnu
    Thread model: posix
    InstalledDir: /usr/lib/llvm-22/bin
    
  • Standard library: libc++ 22

  • C++ language mode: C++26

  • Build type: Release

  • Container operating system: Ubuntu 24.04

  • Host operating system: Linux

Lingua principale
C++
Stelle
3.7k
Fork
914
Merge medio
2g 6h
PR unite (30g)
23

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/DirectXShaderCompiler

Tutte le issue di microsoft/DirectXShaderCompiler

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.