Topic: Macro names and keywords (was Defect report: [lex.key]


Author: greghe@pacbell.net (Greg Herlihy)
Date: Sat, 4 Aug 2007 15:21:13 GMT
Raw View


On 8/3/07 2:01 PM, in article oAKsi.81658$U01.733264@twister1.libero.it,
"Alberto Ganesh Barbati" <AlbertoBarbati@libero.it> wrote:

> Pete Becker ha scritto:
>> On 2007-08-02 17:19:40 -0400, AlbertoBarbati@libero.it (Alberto Ganesh
>> Barbati) said:
>>
>>> James Kanze ha scritto:
>>>>
>>>> (If someone wanted to ban defining keywords as macros entirely,
>>>> I'd be all in favor as well.  But that's another issue, and a
>>>> definite change.)
>>>>
>>>
>>> As a matter of fact, the standard already does it in [macro.names],
>>> paragraph 2: "A translation unit shall not #define or #undef names
>>> lexically identical to keywords."
>>
>> That's from the draft of the next revision of the standard. It's not in
>> the current standard.
>>
>
> Precisely. In the current standard the paragraph reads differently and
> explicitly mentions that the requirement applies only if the program
> tries to include a library header, which makes more sense to me. Now, a
> few questions arise in my mind:
>
> 1) Is the removal of the "only if includes a library header" part
> intentional? I guess so... but...

Yes, see Library Issue #294.

> 2) What is the rationale for such change? Frankly I can't see it. I know
> that redefining a keyword is near to insane, but why forbidding it a priori?

I don't see any rationale either. The defect report that James submitted
(yes, we now have someone to blame :-)) described a translation that
redefines a name equivalent to a library name indirectly included by the
translation unit. There was however no corresponding defect with regards to
a translation that both included a library header and that redefined a
keyword. The behavior of a program in that situation was always undefined -
whether or not the redefined keyword appeared in the included header or not.

So it appears that the rule about redefining keywords was simply "swept up"
in the fix for redefining library names (no doubt because the keyword
sentence made reference to the sentence that needed to be changed).

Now, I am not familiar with the rules or guidelines (if any) concerning how
active issues are to be resolved. But if there is a requirement that only
those changes necessary to resolve the reported defect may be included in
its fix - then this change to the rule about redefining keywords should not
have been made.

Greg

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]