TimeValue.h fails to compile as C++26 with Clang 22
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
include/llvm/Support/TimeValue.h から始め、特に llvm::sys::TimeValue(double) コンストラクターと、110-111 行で特定されている式を確認してください。提供された C++26 clang++ コマンドで失敗を再現し、その後、ヘッダーと提供された TimeValue の例が正常にコンパイルされることを確認してください。
索引モデルが issue の本文から書いたものです。
説明
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:
Steps to Reproduce
-
Check out DXC tag
upstream/v1.9.2607, commit
0d3ee6b551b8fa768fbf825300ebab81047ef6a8. -
Configure the normal generated DXC include directory.
-
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;
}
- 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
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/DirectXShaderCompiler のほかの issue
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
microsoft/DirectXShaderCompiler#9087 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
microsoft/DirectXShaderCompiler#9086 ·
メンテナーはふだん 1 日以内に返信
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
microsoft/DirectXShaderCompiler#9015 ·
メンテナーはふだん 1 日以内に返信
-
bug needs-triage spirv
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
microsoft/DirectXShaderCompiler#8831 ·
メンテナーはふだん 1 日以内に返信
-
bug needs-triage spirv
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
microsoft/DirectXShaderCompiler#8829 ·
メンテナーはふだん 1 日以内に返信
microsoft/DirectXShaderCompiler の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
llvm/offload-test-suite#1703 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
BGI-shenzhen/PopLDdecay#25 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 68/100
eic/TimeframeBuilder#102 ·