So, for the first weekend in ages, I'm actually getting to do some amiga coding.
I have some code that is attempting to span the bridge between gcc 2.95 (on the classic) and 4 (on the A1) as well as under linux.
Unfortunately, somebody decided that GCC 4's preprocessor (and working back through older versions, 3's too probably) needed to be really broken.
I have a macro that uses one of two ways of throwing an exception, depeding on compilation options:
method 1:
#define THROW_NESTED_EXCEPTION(cname, except) EXNGPrivate::throw##cname##except
method 2:
#define THROW_NESTED_EXCEPTION(cname, except) throw cname##::##except
This is the (expected) expansion behaviour that you get with 2.95.x
method1:
THROW_NESTED_EXCEPTION(Foo, InvalidBar()); -> EXNGPrivate::throwFooInvalidBar();
method2:
THROW_NESTED_EXCEPTION(Foo, InvalidBar()); -> throw Foo::InvalidBar();
Both work exactly as expected. Method 1 expands into a debugging function call that handles throwing the exception in a different way (for example, logging that the exception is about to be raised, then raising it).
Under GCC 4, I have ran into this nugget of sheer, unadulterated rubbish when compiling with method 2:
THROW_NESTED_EXCEPTION(Application, TooFewArguments());
/extropia/exng2/libsource/systemlib/startup.cpp:93:1: error: pasting "Application" and "::" does not give a valid preprocessing token
/extropia/exng2/libsource/systemlib/startup.cpp:93:1: error: pasting "::" and "TooFewArguments" does not give a valid preprocessing token
In other words, the preprocessor cannot paste together the macro arguments with the scope of resolution operator without considering the interim result as an invalid token. Why for pity's sake?
Searching for this class of error, I find thousands of links (mostly about pasting with "." however) but no actual explanation as to why this is considered an error.
I'm not attempting to stringify (#) the arguments, I just want it to concatenate the arguments in the specified manner and emit the damn code.
Anybody come across this behaviour before?