This is the mail archive of the gcc@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 token pasting, 2.95 vs 3.0


Justin Guyett wrote:-

> lines containing things like
> 
>     foo.y ## 2.clear()
> 
> worked in 2.95.  Is it expected and proper that in 3.0+ this should be

Unforunately, "expected and proper" is not how compilers work.

>     foo.bar ## 2 ## .baz()
> 
> and is there any workaround to all the warnings the second form generates?
> 
> ../test.h:32:9: warning: pasting "bar2" and "." does not give a valid
> preprocessing token

CPP is correct, and the message is pretty clear, at least if you
understand what the semantics of ## really are.

I suspect you have a macro somewhere that is doing

#define foo(A, B) foo.A ## B ## .baz

In this particular case, the 2nd ## is not helping and you should just
delete it.

If this is not your situation, then you need to understand what ##
really means, and find a different way to do whatever it is you want.
We may turn the current warning into a hard error in future - after
all, the preprocessor is not managing to paste tokens that you are
asking it to.  Something being two tokens rather than one can change
the meaning of a program, particularly if you were relying on some
kind of textual token paste owing to a second lexer scan like GCC used
to do.

Neil.


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