http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48741
vjeux changed:
What|Removed |Added
Summary|c |c++0x ##__VA_ARGS__ no
||longer remove , without
||arguments
--- Comment #1 from vjeux 2011-04-23 10:41:10 UTC ---
In C99, when using ##__VA_ARGS__ in a variadic macro has a special feature. If
the macro is called with 0 arguments AND there is a comma before, then it is
removed.
This is a handy feature that is no longer working with std=c++0x. I believe
that this is an unintentional feature and that it should be fixed.
TEST CASE
test.cpp
#define variadic(...) func(first, ##__VA_ARGS__)
variadic()
variadic(1)
variadic(1, 2)
== Output of std=C++0x (Bug)
> cpp test.cpp -std=c++0x
func(first,)
func(first,1)
func(first,1, 2)
== Output (Expected)
> cpp test.cpp -std=c99
func(first)
func(first,1)
func(first,1, 2)
> cpp --version
cpp (GCC) 4.7.0 20110419 (experimental)
DOCUMENTATION
---
http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html
Second, the `##' token paste operator has a special meaning when placed between
a comma and a variable argument. If you write
#define eprintf(format, ...) fprintf (stderr, format, ##__VA_ARGS__)
and the variable argument is left out when the eprintf macro is used, then the
comma before the `##' will be deleted. This does not happen if you pass an
empty argument, nor does it happen if the token preceding `##' is anything
other than a comma.