Skip to content

<cmath>: Support /Zc:cmath downlevel - #6425

Merged
Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:mainfrom
StephanTLavavej:downlevel-cmath
Sep 3, 2026
Merged

Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:mainfrom
StephanTLavavej:downlevel-cmath

Conversation

@StephanTLavavej

Copy link
Copy Markdown
Member

Followup to #6413. Cody Miller (@Codiferous) noticed that while MSVC supports /Zc:cmath downlevel (i.e. in C++14/17/20 before C++23) and rewrites <math.h> to <__msvc_math.hpp> which always uses builtins, our <cmath> used /Zc:cmath builtins only in C++23 mode. In downlevel modes, it fell back to intrinsics, which created conflicts between libc math and UCRT math.

The fix is to generalize <cmath> to use builtins when they're available under /Zc:cmath regardless of Standard mode. Marking our functions as constexpr is still controlled by the Standard mode.

This PR then significantly enhances test coverage to cover downlevel modes. This is the first time that our test suite explicitly acknowledges the difference between /std:c++23preview and /std:c++latest, which I will be introducing at a larger scale later.

Copilot AI balanced review requested due to automatic review settings August 31, 2026 19:23
@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) added the bug Something isn't working label Aug 31, 2026
@github-project-automation github-project-automation Bot moved this to Initial Review in STL Code Reviews Aug 31, 2026
@azure-pipelines

This comment was marked as resolved.

This comment was marked as resolved.

@frederick-vs-ja

Copy link
Copy Markdown
Contributor

Will this resolve the performance issue in #4998?

@StephanTLavavej

Stephan T. Lavavej (StephanTLavavej) commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

Yes, I think so. However, I haven't looked at the codegen.

@StephanTLavavej

Copy link
Copy Markdown
Member Author

I'm mirroring this to the MSVC-internal repo. Please notify me if any further changes are pushed, otherwise no action is required.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Before approving, I have some questions about downstream effects. I'll confirm some thing internally :-]

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) moved this from Final Review to Merging in STL Code Reviews Sep 3, 2026
@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit bcf405a into microsoft:main Sep 3, 2026
48 checks passed
@github-project-automation github-project-automation Bot moved this from Merging to Done in STL Code Reviews Sep 3, 2026
Charlie Lin (clin1234) pushed a commit to clin1234/STL that referenced this pull request Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants