[cfe-commits] [Patch] Fix for comma-removal ahead of __VA_ARGS__ in macros

Andy Gibbs andyg1001 at hotmail.co.uk
Mon Nov 5 11:22:21 PST 2012


On Monday, November 05, 2012 6:50 PM, Eli Friedman wrote:
> On Mon, Nov 5, 2012 at 3:07 AM, Andy Gibbs wrote:
>> Here is the line from the gcc help: "... In this case the C99 standard is
>> clear that the comma must remain, however the existing GCC extension used 
>> to
>> swallow the comma. So CPP retains the comma when conforming to a specific 
>> C
>> standard, and drops it otherwise."
>
> Ah, yes... but that text only applies in the case where the macro has
> zero named arguments.

You are right.  I had overlooked this and not realised this was the case.

Ok, I've extended the test case to the following...

#define A(...)   [ __VA_ARGS__ ]
#define B(...)   [ , __VA_ARGS__ ]
#define C(...)   [ , ## __VA_ARGS__ ]
#define D(A,...) [ A , ## __VA_ARGS__ ]
#define E(A,...) [ __VA_ARGS__ ## A ]

1: A()      B()      C()      D()      E()
2: A(a)     B(a)     C(a)     D(a)     E(a)
3: A(,)     B(,)     C(,)     D(,)     E(,)
4: A(a,b,c) B(a,b,c) C(a,b,c) D(a,b,c) E(a,b,c)
5: A(a,b,)  B(a,b,)  C(a,b,)  D(a,b,)

// GCC: 1: [ ] [ , ] [ ] [ ] [ ]
// GCC: 2: [ a ] [ , a ] [ ,a ] [ a ] [ a ]
// GCC: 3: [ , ] [ , , ] [ ,, ] [ , ] [ ]
// GCC: 4: [ a,b,c ] [ , a,b,c ] [ ,a,b,c ] [ a ,b,c ] [ b,ca ]
// GCC: 5: [ a,b, ] [ , a,b, ] [ ,a,b, ] [ a ,b, ]

// C99: 1: [ ] [ , ] [ , ] [ ] [ ]
// C99: 2: [ a ] [ , a ] [ ,a ] [ a ] [ a ]
// C99: 3: [ , ] [ , , ] [ ,, ] [ , ] [ ]
// C99: 4: [ a,b,c ] [ , a,b,c ] [ ,a,b,c ] [ a ,b,c ] [ b,ca ]
// C99: 5: [ a,b, ] [ , a,b, ] [ ,a,b, ] [ a ,b, ]

// MS: 1: [ ] [ ] [ ] [ ] [ ]
// MS: 2: [ a ] [ , a ] [ ,a ] [ a ] [ a ]
// MS: 3: [ , ] [ , , ] [ ,, ] [ ] [ ]
// MS: 4: [ a,b,c ] [ , a,b,c ] [ ,a,b,c ] [ a ,b,c ] [ b,ca ]
// MS: 5: [ a,b, ] [ , a,b, ] [ ,a,b, ] [ a ,b, ]

The comments show the expected output, not what clang currently outputs (GCC 
= -std=gnuxx; C99 = -std=c99; MS = VC++).

Can you think of any further pertinent tests that I have omitted, or does 
that now cover it?

Thanks ever so much for your help,

Andy
 




More information about the cfe-commits mailing list