Repository navigation
<__msvc_math.hpp>: Respect _USE_MATH_DEFINES on every inclusion - #6534
Open
Tiago (tiagomacarios) wants to merge 1 commit into
Open
Tiago (tiagomacarios) wants to merge 1 commit into
Tiago (tiagomacarios) wants to merge 1 commit into
Conversation
Fixes microsoft#6532. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change honoring late _USE_MATH_DEFINES opt-in on repeated inclusion.
No open issues 🎉
What changed in this PR
Fixes #6532 by making <__msvc_math.hpp> honor _USE_MATH_DEFINES on repeated inclusion under /Zc:cmath, matching UCRT behavior.
Changes:
- Moves the math-constant inclusion outside the header guard while retaining the
_STL_COMPILER_PREPROCESSORcondition. - Adds regression coverage for defining
_USE_MATH_DEFINESafter an earlier<math.h>inclusion.
| File | Description |
|---|---|
| tests/std/tests/P0533R9_constexpr_for_cmath_and_cstdlib/test.cpp | Verifies that late opt-in exposes M_PI with the expected value. |
| stl/inc/__msvc_math.hpp | Checks _USE_MATH_DEFINES on every inclusion and documents why. |
Review effort: Balanced
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6532.
AI disclosure: the header and test changes and this description were written with GitHub Copilot, and checked as described under Testing.
<__msvc_math.hpp>checks_USE_MATH_DEFINESinside its include guard, so under/Zc:cmaththe macro only works when it's defined before the first<math.h>. The UCRT's<math.h>checks it on every inclusion, so code that defines_USE_MATH_DEFINESand includes<math.h>after a precompiled header or<cmath>already did losesM_PIwhen it moves to/Zc:cmath. This moves the check after the include guard, keeping the_STL_COMPILER_PREPROCESSORcondition. Repeated#include <math.h>now re-opens the header, as the UCRT's does.Testing: extended the existing
_USE_MATH_DEFINEScheck inP0533R9_constexpr_for_cmath_and_cstdlibwith the late-definition case. Locally with MSVC Build Tools 14.52.37025 (not the Preview toolset) and this branch's headers, the 20/Zc:cmathconfigurations without/D_USE_MATH_DEFINESfail onmainwithC2065 'M_PI'and pass with the change; all 57 configurations I could run (everything except ASan, clang-cl,/clr,/BE,/analyze) compile, link and run. clang-format andvalidateare clean.