Re: Possible __VA_OPT__ bug

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/31/2019 1:14 PM, Segher Boessenkool wrote:
Hi Edward,

On Thu, Oct 31, 2019 at 12:42:54PM -0400, Edward Diener wrote:
Given:

#define NO_DATA
#define TRY_VA_OPT(...)  __VA_OPT__ (0) 1

TRY_VA_OPT() -> expands to 1 as expected
TRY_VA_OPT(NO_DATA) -> expands to 0 1 which is not expected

when compiled with gcc-9.2 with -std=c++2a.

Why is that not expected?  The variadic macro TRY_VA_OPT does get tokens
in its variable argument (namely, NO_DATA), so __VA_OPT__ expands to its
argument (which is 0).

https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html

The wording of 15.6.1 paragraph 3 is confusing to me. I had thought that the arguments to the variadic ... parameter were completely macro expanded before considering whether the __VA_OPT__ ( pp-tokens ) would expand to 'pp_tokens' or a single placemarker token. Evidently you are saying that the correct interpretation with the __VA_OPT__ construct is that the variadic ... arguments are not macro expanded before consideration of the __VA_OPT__ construct processing . This seems to me very odd because the arguments to the variadic ... parameter are always completely macro expanded before being replaced by any __VA_ARGS__ parameter in the replacement list. I wonder why the C++ standard committee decided to treat __VA_OPT__ differently from __VA_ARGS__ in this regard ?



Segher






[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux