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

Aaron Ballman aaron at aaronballman.com
Wed Dec 17 16:03:59 PST 2014


On Tue, Dec 16, 2014 at 4:17 PM, Nico Weber <thakis at chromium.org> wrote:
> Ok, I moved -Wkeyword-macro into -pedantic in r224371. I also removed
> -Wreserved-id-macro in the same revision, as it's not covered by the
> standards bit you cited

I do not think -Wreserved-id-macro should be removed entirely, but I
do think it should have a heuristic update before being recommitted,
and is too chatty to leave in currently.

[global.names] specifies that those names are reserved to the
implementation, but implementations may require use of them. For
instance, __need_size_t may need to be #defined before including
<stddef.h>, and that's valid because the implementer expects that.
However, __MY_SILLY_HEADER_GUARD__ should not be allowed.

One heuristic which may work would be to make it only trigger on
header include guards when defining macros and to always trigger on
nonmacro names (and never in system headers). I'm not certain how
chatty such a heuristic would be, but it would have less false
positives than the previous patch did.

FWIW, this can pick out real problems -- I ran into this myself when
working on tablegenning attribute code, which would accidentally
create identifiers like foo__bar, which are reserved to the
implementation.

~Aaron



More information about the cfe-commits mailing list