[Bug preprocessor/48741] New: c

2011-04-23 Thread vjeuxx at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48741

   Summary: c
   Product: gcc
   Version: 4.7.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: preprocessor
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: vje...@gmail.com


[Bug preprocessor/48741] c++0x ##__VA_ARGS__ no longer remove , without arguments

2011-04-23 Thread vjeuxx at gmail dot com
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.


[Bug preprocessor/48741] c++0x ##__VA_ARGS__ no longer remove comma without arguments

2011-04-23 Thread vjeuxx at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48741

--- Comment #3 from vjeux  2011-04-23 16:30:57 UTC ---
(In reply to comment #2)
> This is a C99 feature and a GNU extension in C++.  Use -std=gnu++0x.

Thanks, I did not know about this.