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

未关闭 适合新手
#8,992 0 条评论 0 个 reaction 已指派 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 小时
30 天内合并 PR
21

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/DirectXShaderCompiler 的其他 Issue

查看 microsoft/DirectXShaderCompiler 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。