This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: preprocessor token pasting, 2.95 vs 3.0
- To: Neil Booth <neil at daikokuya dot demon dot co dot uk>
- Subject: Re: preprocessor token pasting, 2.95 vs 3.0
- From: Justin Guyett <jfg at sonicity dot com>
- Date: Thu, 21 Jun 2001 16:12:04 -0700 (PDT)
- Cc: <gcc at gcc dot gnu dot org>
On Wed, 20 Jun 2001, Neil Booth wrote:
> > ../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
except B is always a number.. see below.
> In this particular case, the 2nd ## is not helping and you should just
> delete it.
gcc 3.0 errors if you do that.
sorry if this was unclear. The code has some monstrous multi-line macros.
the portion in question was originally this:
#define A(x) do { \
func.x ## 2.clear(); \
} while(0)
gcc 2.95 has no problems pasting func.x with 2.clear(), but gcc 3 does
(error "invalid suffix on floating constant", it thinks 2 is a number,
since functions can't start with numeric digits and it hasn't done the
pasting yet). gcc 2.95's interpretation makes sense, gcc 3.0 doesn't.
Nobody cares if it's a number, if it's right after a ##, it's getting
pasted onto something else so any ideas about what it is or what it's part
of should be suspended until after the pasting.
with gcc 3.0, changing to "func.x ## 2 ## .clear();" works, but gives
the error: (presuming foo is passed to the macro)
../test.h:32:9: warning: pasting "foo" and "." does not give a valid
preprocessing token
so e.g. if foo is passed as x, is there any way to do the equivalent of
func.foo2.clear();
without getting that warning, and if it's changed to an error, how would
you do something like that?
simple test code: try compiling this with gcc 2.95.x and gcc 3... this
won't compile at all with gcc 3, compiles perfectly with 2.95, but
illustrates the point i think.
#include <list>
#define T(x) (func.x ## 2.clear())
struct a {
std::list<int> foo2;
};
int main(int argc, char **argv) {
struct a func;
T(foo);
return(0);
}
with gcc 3.0 you'll find it doesn't compile, and requires you to change
the macro to
... ## 2 ## .clear())
and you still get the warning, which is what I was trying to find a way
around...
justin