Bug 98859 - pedantic error on use of __VA_OPT__ before C++20 is unnecessary and counterproductive
Summary: pedantic error on use of __VA_OPT__ before C++20 is unnecessary and counterpr...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2021-01-27 20:52 UTC by Richard Smith
Modified: 2022-11-19 11:58 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-01-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Smith 2021-01-27 20:52:45 UTC
There's no good way in ISO C or C++ to express what the GNU ,##__VA_ARGS__ extension does prior to the addition of __VA_OPT__. However, code targeting new compilers (that doesn't want to use GNU C / GNU C++) cannot reliably use __VA_OPT__ instead of the comma paste extension, because GCC's -pedantic-errors mode rejects it outside C++20.

Such rejection is unnecessary: __VA_OPT__ is a reserved identifier in other language modes, so there is no conformance reason to issue a diagnostic on its use. I think it'd be useful for GCC to unconditionally allow using __VA_OPT__ in all language modes. (I'm changing Clang to do the same.)
Comment 1 Marek Polacek 2021-01-27 20:54:40 UTC
That sounds reasonable.
Comment 2 Yongwei Wu 2021-07-30 15:49:35 UTC
Here is anotehr good reason:

https://stackoverflow.com/questions/48045470/portably-detect-va-opt-support/48045656

People can detect the presence of __VA_OPT__ support. Currently, the detection code would cause warnings when -std is set to something like "c++17" (though luckily not "gnu++17").
Comment 3 Will Wray 2022-11-19 11:58:03 UTC
Linking the related MSVC issue

/Zc:preprocessor __VA_OPT__ is not enabled with /std:c++17
https://developercommunity.visualstudio.com/t/Zc:preprocessor-__VA_OPT__-is-not-enabl