I'm moving some code over to GCC 4.7 (from 4.6) and ran into a few compiler errors and found the problem documented in the GCC 4.7 porting guide:
User-defined literals and whitespace
The C++ compiler in ISO C11 mode
std={c++11,c++0x,gnu++11,gnu++0x}
supports user defined literals, which are incompatible with some valid ISO C++03 code.In particular, whitespace is now needed after a string literal and before something that could be a valid user defined literal. Take the valid ISO C++03 code
const char *p = "foobar"__TIME__;
In C++03, the TIME macro expands to some string literal and is concatenated with the other one. In C++11
__TIME__
isn't expanded, insteadoperator "" __TIME__
is being looked up, resulting in the following diagnostic:error: unable to find string literal operator ‘operator"" __TIME__’
This applies to any string literal followed without whitespace by some macro. To fix, just add some whitespace between the string literal and the macro name.
While I could fix the errors, I'd like to know why I must do this. __TIME__
is a macro, so "something"__TIME__
would change into "something""15:52:03"
(or similar) in the preprocessing stage, so the compiler would never have the opportunity to see it as operator ""
.
Is this behavior standards-approved or is it a bug?