r224012 - Emit warning if define or undef reserved identifier or keyword.

Aaron Ballman aaron at aaronballman.com
Mon Dec 15 08:32:02 PST 2014


On Sat, Dec 13, 2014 at 2:46 PM, Joerg Sonnenberger
<joerg at britannica.bec.de> wrote:
> On Thu, Dec 11, 2014 at 12:18:09PM -0000, Serge Pavlov wrote:
>> Author: sepavloff
>> Date: Thu Dec 11 06:18:08 2014
>> New Revision: 224012
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=224012&view=rev
>> Log:
>> Emit warning if define or undef reserved identifier or keyword.
>
> So I see valid applications for:
>
> (1) #define const const, #define inline inline, etc --> autoconf has
> been doing that a lot.

I agree, this seems like a perfectly valid application.

> (2) #define restrict __restrict__ --> code that has to deal with pre-C99
> default in GCC.

I'm not certain this should have triggered the warning in the first
place. Either restrict is a keyword (at which point, the #define
should be considered possibly harmful), or restrict isn't a keyword
(and then there's no reason for the warning in the first place).

> (3) #define extern, #define static --> debug, code sharing

I think these should be a warning. If you're doing a debug build where
you want to turn off keywords, you can add a -Wno-keyword-macro flag
to your command line.

This commit appears to be lacking tests, and I would like to see some
added for each of the new diagnostics, as well as for cases that
should be valid (such as keywords in language modes that do not have
the keyword).

~Aaron



More information about the cfe-commits mailing list