This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Preprocessor bug



Unfortunately I do not have enough information to know what the Standard
says, it has been a long time since I was part of those committees.  However
I do know that every compiler that I have tested (Sunpro, SGI, HP, AIX,
MSVC, GCC2.95.2) all of them handle this as I expected them to.  Now this
might be incorrect behavior according to the standard, but because all of
them support this incorrect behavior it means that this has become the
expected behavior.  So if nothing else, we should have a compatibility flag
that reverts to the old behavior.  I would expect there to be very little
(if any) code that requires this new behavior.  But I would expect there to
be a lot of existing code that requires the old behavior.

I strongly believe in being standards compliant; however, I also believe in
maintaining portability.

What solution can we find that is the best for the entire C/C++ community?
One that allows older (non-standard conforming) code to work and one that
allows newer (conforming) code to work?

John


-----Original Message-----
From: Neil Booth [mailto:neilb@earthling.net]
Sent: Tuesday, November 21, 2000 12:19 PM
To: Martin Sebor
Cc: John Hinke; gcc-bugs@gcc.gnu.org; John Pedretti
Subject: Re: Preprocessor bug


Martin Sebor wrote:-

> Yes, although I don't agree that the two examples exploit the same
> feature. You're talking about 6.10.3.4, p2, which is not relevant in
> John's example. Here's a simplified testcase which I'm pretty sure is
> well-formed and should produce, (what else?), foobar:

I don't agree.

> #define __paste(a,b)      a##b
> #define paste(a,b)        __paste(a, b)
> 
> #define declfoo(a)        paste(foo, a)
> #define declare(a, b)     paste(decl, a)(b)
> 
> declare(foo, bar)

declare(foo, bar)
  paste(decl, foo)(bar)
    declfoo(bar)
      paste(foo, bar)  [*]

Again, it's a nested expansion, so the nested one doesn't expand.  You
can only traverse each stage to get to [*] by rescanning the result of
the previous macro expansion for new macros to expand, and rescanning
is not permitted to expand already-expanded macros.  The standard is
pretty clear about this.

"paste(foo, bar)" is what cpp currently gives, correctly IMO.

Neil.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]