Skip to content

Conversation

@puetzk
Copy link
Contributor

@puetzk puetzk commented Mar 28, 2025

  • Add VS2019 and VS2022 runs where __cplusplus >= 202002L is combined with /Zc:preprocessor- (and fail to preprocess correctly).

See https://github.com/puetzk/trompeloeil/actions/runs/14110751749 for an example where the new CI configurations (without the corresponding fix) fail to compile, because they try to use __VA_OPT__ in a configuration where the preprocessor does not support it.

With the second commit (fixing the detection macro), all of the configurations now run, three of them with different behavior:

  • "Windows MSVC 2019 C++20 preprocessor" should detect that it does have __VA_OPT__ (because it's >= 16.6, /Zc:preprocessor is on, and /std:c++20 was set, making _MSVC_TRADITIONAL=0 and _MSVC_LANG=202002L.

  • "Windows MSVC 2019 C++20 __cppstd" and "Windows MSVC 2022 C++20 __cppstd" now see that they do not have __VA_OPT__ (because it's using the old preprocessor, despite being __cplusplus >= 202002L

Fixes #343

puetzk added 2 commits March 27, 2025 10:40
Demonstrate bug rollbear#343 - since MSVC offers individual options to control
/std:c++20, /Zc:__cplusplus, and /Zc:preprocessor, it's possible to have
a combination where the compiler is in C++20 mode (and says so), but
the traditional preprocessor (which not support __VA_OPT__) is in use.

This configuration is commonly trigged by Qt6, which requires c++17,
suggests c++20, sets /Zc:__cpluspls (so it can #ifdef based on compiler),
but doesn't care about the preprocessor. MSVC still doesn't enable the
new /Zc:preprocessor by default, even with /std:c++20 or /permissive-.
Only the new conformant MSVC preprocessor (_MSVC_TRADITIONAL==0) ever has
__VA_OPT__. This became avaialble with Visual Studio 16.6, but only if
running in /std:c++20 or /std:c++latest mode (i.e. _MSVC_LANG > c++17).
- https://devblogs.microsoft.com/cppblog/announcing-full-support-for-a-c-c-conformant-preprocessor-in-msvc/

Starting with Visual Studio 17.10, it is now enabled regardless of /std
This was changed to better match the behavaior of GCC and clang,
which also loosened up their checks:
- https://developercommunity.visualstudio.com/t/Zc:preprocessor-__VA_OPT__-is-not-enabl/10205604
- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98859
  (GCC 13 and up allow __VA_OPT__ in -std=c2x as well as -std=c++20)
- https://reviews.llvm.org/D91913
  (clang 12 and up allow __VA_OPT__ regardless of c/c++ standard)

The MSVC traditional preprocessor (_MSVC_TRADITIONAL defined and nonzero)
never supports __VA_OPT__, regardless of MSVC or c++ standard version.
@codecov
Copy link

codecov bot commented Mar 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.41%. Comparing base (eaeb89c) to head (cb808e2).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #345   +/-   ##
=======================================
  Coverage   99.40%   99.41%           
=======================================
  Files          15       15           
  Lines        1344     1361   +17     
  Branches       21       22    +1     
=======================================
+ Hits         1336     1353   +17     
  Misses          8        8           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rollbear rollbear merged commit c8214a0 into rollbear:main Mar 30, 2025
147 checks passed
@rollbear
Copy link
Owner

Awesome! Thank you so much!

@puetzk puetzk deleted the _MSVC_TRADITIONAL-__VA_OPT__ branch March 30, 2025 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Traditional MSVC preprocessor does not have __VA_OPT__, even c++20 mode

2 participants