This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
preprocessor/3852: cpp: parantheses wrong in variable argument macros
- To: gcc-gnats at gcc dot gnu dot org
- Subject: preprocessor/3852: cpp: parantheses wrong in variable argument macros
- From: asbrown at ati dot com
- Date: 28 Jul 2001 02:06:06 -0000
- Reply-To: asbrown at ati dot com
>Number: 3852
>Category: preprocessor
>Synopsis: cpp: parantheses wrong in variable argument macros
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Jul 27 19:16:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: asbrown@ati.com
>Release: gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
sparc-sun-solaris2.6
>Description:
I was using the variable macro arguments feature of cpp and I noticed some problems with the parantheses. I haven't tried it on gcc 3.0.
Here is the source to test.c:
// here's something that works
#define TEST_GOOD(foo, args...) (foo, ## args)
// here's a variation that doesn't
#define TEST_BAD(foo, args...) (0, (foo), ## args)
// this is simpler and needs an argument to work
#define TEST_WORSE(args...) (0, ## args)
void main() {
TEST_GOOD(0); // works
TEST_BAD(0); // doesn't work
TEST_WORSE(0); // works
TEST_WORSE(); // doesn't work
}
If I run cpp test.c, I get
# 1 "test.c"
void main() {
( 0 ) ;
(0, ( 0 ) ;
(0,0 ) ;
) ;
}
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: