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 小时
- 30 天内合并 PR
- 21
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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
-
Linux npm packaging leaves workspace files that block subsequent CI checkout可能已有人在做 @Spockkk0225 今天认领。 未关闭ci
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 3 天内回复
-
QA/No release-notes/exclude tests tests/missing-coverage tests/test-quality
难度 2/5 1-3 小时 新手友好度 71/100
brave/brave-browser#61019 ·
维护者通常 1 天内回复
-
? - Needs Triage bug CUTLASS C++
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 4 天内回复