https://gcc.gnu.org/bugzilla/show_bug.cgi?id=33877

--- Comment #9 from Alejandro Colomar <foss+...@alejandro-colomar.es> ---
GCC's ## __VA_ARGS__ seems to differ from __VA_OPT__(), and seems to agree with
the more intuitive interpretation of number of arguments.

alx@debian:~/tmp$ cat vo.c | nl -ba
     1  #define foo(...)     __LINE__: foo: __VA_OPT__(nonzero args:
__VA_ARGS__)
     2  #define bar(a, ...)  __LINE__: bar: __VA_OPT__(nonzero args:
__VA_ARGS__)
     3  
     4  foo()
     5  foo(x)
     6  foo(,)
     7  
     8  bar(a)
     9  bar(a,)
    10  bar(a,b)
    11  
    12  #define f(...)     __LINE__: f:, ## __VA_ARGS__
    13  #define b(a, ...)  __LINE__: b:, ## __VA_ARGS__
    14  
    15  f()
    16  f(x)
    17  f(,)
    18  
    19  b(a)
    20  b(a,)
    21  b(a,b)
alx@debian:~/tmp$ g++ -E vo.c | grep -v ^# | uniq

4: foo:
5: foo: nonzero args: x
6: foo: nonzero args: ,

8: bar:
9: bar:
10: bar: nonzero args: b

15: f:
16: f:,x
17: f:,,

19: b:
20: b:,
21: b:,b


GCC's ## __VA_ARGS__ seems to consider that lines 15 and 19 get 0 arguments,
while all others get one or more.  I think __VA_OPT__() is badly specified in
the standard and should be fixed.

Reply via email to