[cfe-commits] [PATCH] Suppress elided variadic macro argument diagnostic with comma pasting extension

Richard Smith richard at metafoo.co.uk
Mon Nov 12 15:49:43 PST 2012


On Mon, Nov 12, 2012 at 2:48 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
> Is anyone planning to look at this patch?

Patch looks fine, but the approach makes me very slightly nervous (if
the two warnings ever get put into different warning groups, and only
the empty-vararg-list warning is enabled, we'll incorrectly suppress
it).

As an alternative, could we disable the comma-pasting diagnostic for a
macro with any parameters?

> On Fri, Nov 9, 2012 at 7:01 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
>> Suppose you have a testcase like the following:
>>
>> #define NSAssert(condition, desc, ...) \
>>     SomeComplicatedStuff((desc), ##__VA_ARGS__)
>> NSAssert(somecond, somedesc)
>>
>> We currently print two diagnostics:
>>
>> <stdin>:3:28: warning: must specify at least one argument for '...'
>> parameter of variadic macro [-Wgnu]
>> NSAssert(somecond, somedesc)
>>                            ^
>> <stdin>:1:9: note: macro 'NSAssert' defined here
>> #define NSAssert(condition, desc, ...) \
>>         ^
>> <stdin>:2:32: warning: token pasting of ',' and __VA_ARGS__ is a GNU
>> extension [-Wgnu]
>>     SomeComplicatedStuff((desc), ##__VA_ARGS__)
>>
>>
>> The attached patch suppresses the first diagnostic in certain cases
>> where we know we're going to print the second diagnostic.  The
>> diagnostic is redundant, and it can't be suppressed in the definition
>> of the macro because it points at the use of the macro, so we want to
>> avoid printing it if possible.
>>
>> The implementation works by detecting constructs which look like comma
>> pasting at the time of the definition of the macro; this information
>> is then used when the macro is used.  (We can't actually detect
>> whether we're using the comma pasting extension until the macro is
>> actually used, but we can detecting constructs which will be comma
>> pasting if the varargs argument is elided.)
>>
>> I'm asking for a review because I'm not very familiar with this code.
>>
>> -Eli
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list