Skip to content

[Support] Explicitly cast NANOSECONDS_PER_SECOND in TimeValue for C++26 - #9021

Open
Reginald Alfret V (reginaldalfret) wants to merge 4 commits into
microsoft:mainfrom
reginaldalfret:fix/issue-8992-cpp26-timevalue-enum
Open

Reginald Alfret V (reginaldalfret) wants to merge 4 commits into
microsoft:mainfrom
reginaldalfret:fix/issue-8992-cpp26-timevalue-enum

Conversation

@reginaldalfret

Copy link
Copy Markdown

[Support] Explicitly cast NANOSECONDS_PER_SECOND in TimeValue for C++26

  • Cast NANOSECONDS_PER_SECOND enum to double in llvm::sys::TimeValue(double) constructor
  • Resolves build failure when consuming DXC headers under Clang 22 with -std=c++26

Fixes #8992

Description

Arithmetic between floating-point types and enumeration types was deprecated in C++20 and removed in C++26 by WG21 P2864R2.

In include/llvm/Support/TimeValue.h, line 111:

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

Under Clang 22 with -std=c++26, this produces:
error: invalid arithmetic between floating-point type 'double' and enumeration type 'llvm::sys::TimeValue::TimeConversions'

Explicitly casting NANOSECONDS_PER_SECOND to double resolves the compilation failure while preserving exact numerical semantics in all C++ standards.

Arithmetic between floating-point types and enumeration types was deprecated
in C++20 and removed in C++26 by WG21 P2864R2. This caused Clang 22 with
-std=c++26 to fail compiling include/llvm/Support/TimeValue.h.

Explicitly cast NANOSECONDS_PER_SECOND to double to ensure compatibility
with C++26 compilers.

Fixes microsoft#8992

Signed-off-by: reginaldalfret <reginaldalfret@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 9, 2026 09:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@damyanp

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The C++26 compilation fix lacks automated regression coverage or an explanation of why such testing is infeasible.

2 open findings

🧠 Review effort: Balanced

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added release note to docs/ReleaseNotes.md under ### Upcoming Release -> #### Bug Fixes.

Comment on lines +110 to +112
nanos_ = static_cast<NanoSecondsType>(
(new_time - static_cast<double>(integer_part)) *
static_cast<double>(NANOSECONDS_PER_SECOND));

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a unit test in unittests/Support/TimeValueTest.cpp covering the sys::TimeValue(double) constructor. As noted in CONTRIBUTING.md:145-157 regarding changes for external projects and test infrastructure limitations, DXC's host build environment and test suite compile in C++14/C++17 across all CI runners and do not provide a Clang 22 / -std=c++26 toolchain to run compile-only C++26 tests directly in CI.

Copilot AI balanced review requested due to automatic review settings October 9, 2026 17:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@damyanp

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Copilot AI balanced review requested due to automatic review settings October 19, 2026 07:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 19, 2026 08:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

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

3 participants