Topic: Macro names and keywords (was Defect report: [lex.key] and [lex.operators]
Author: AlbertoBarbati@libero.it (Alberto Ganesh Barbati)
Date: Fri, 3 Aug 2007 21:01:12 GMT Raw View
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...
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?
3) If the committee really intends the requirement to apply to any
program indiscriminately and without any relationship to the library,
why is it still listed in clause [library]? Wouldn't [cpp.replace] be a
better place for it?
Just my two eurocent,
Ganesh
PS: By the way, the only case where I found useful defining a macro with
the same name as a keyword is precisely with "new", which was the
subject of the OP.
---
[ 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 ]