Preprocessor bug

Neil Booth neilb@earthling.net
Tue Nov 21 12:19:00 GMT 2000


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.


More information about the Gcc-bugs mailing list