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

オープン 初心者向け
#8,992 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@reginaldalfret がすでに取り組んでいます。

2026年10月9日 から。

  • #9021 @reginaldalfret による — オープン

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
92/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp
領域
compilers

調査の方向性

include/llvm/Support/TimeValue.h から始め、特に llvm::sys::TimeValue(double) コンストラクターと、110-111 行で特定されている式を確認してください。提供された C++26 clang++ コマンドで失敗を再現し、その後、ヘッダーと提供された TimeValue の例が正常にコンパイルされることを確認してください。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
C++
スター
3.7k
フォーク
914
平均マージ
3日 23時間
マージ済み PR(30日)
21

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/DirectXShaderCompiler のほかの issue

microsoft/DirectXShaderCompiler の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。