[cfe-dev] #define keyword

James Dennett james.dennett at gmail.com
Thu Jun 20 11:53:31 PDT 2013


On Thu, Jun 20, 2013 at 10:01 AM, Eli Friedman <eli.friedman at gmail.com> wrote:
> On Thu, Jun 20, 2013 at 9:53 AM, Seth Cantrell <seth.cantrell at gmail.com>
> wrote:
>>
>> C++11 [macro.names] 17.6.6.3.1 p2 states
>>
>> > A translation unit shall not #define or #undef names lexically identical
>> > to keywords, to the identifiers listed in Table 3, or to the
>> > attribute-tokens described in 7.6.
>>
>> As I understand it this means a program that does this is ill-formed,
>> with a diagnostic required. Clang does not produce any diagnostics for
>> such defines/undefs. Am I correct that a diagnostic is required? This
>> doesn't sound like it would be too difficult to implement. Is there a
>> reason not to have clang produce a warning for this (one that wouldn't
>> trigger in system headers)?
>
>
> Given that the requirement is buried in the C++ standard library section,
> and there isn't any particular reason to ban #define'ing a keyword for
> translation units which don't include the standard library, I would assume
> that it's only meant to apply to translation units which include the
> standard library.  (I could be wrong, though.)

That's the intention, yes.  The behavior of

#define while(x) while(!(x))

is well-defined, so long as you don't use standard library headers in
the same TU.

-- James



More information about the cfe-dev mailing list