c++ - Weird g++ preprocessor behavior in c++11 mode -


i have problem when g++ run in c++11 mode, proprocessor macros not expanded correct. causes me troubles during compilation of programs using qt.

$ g++ --version g++ (gcc) 4.7.2 copyright (c) 2012 free software foundation, inc. free software; see source copying conditions.  there no warranty; not merchantability or fitness particular purpose. 

the following snipped exposes problem:

$ cat foo.cpp //#include <qtgui> #define qtostring_helper(s) #s #define qtostring(s) qtostring_helper(s) #ifndef qt_no_debug # define qlocation "\0"__file__":"qtostring(__line__) # define method(a)   qflaglocation("0"#a qlocation) # define slot(a)     qflaglocation("1"#a qlocation) # define signal(a)   qflaglocation("2"#a qlocation) #else # define method(a)   "0"#a # define slot(a)     "1"#a # define signal(a)   "2"#a #endif  method(grml) 

preprocesing without c++11 right thing.

$ g++ -e foo.cpp # 1 "foo.cpp" # 1 "<command-line>" # 1 "foo.cpp" # 15 "foo.cpp" qflaglocation("0""grml" "\0""foo.cpp"":""15") 

but in c++11 mode qtostring macro not expanded, causing compile error @ source line.

$ g++ -std=c++11 -e foo.cpp # 1 "foo.cpp" # 1 "<command-line>" # 1 "foo.cpp" # 15 "foo.cpp" qflaglocation("0""grml" "\0"__file__":"qtostring(15)) 

is behavior intended, , can enable expansion?

this known problem , new gcc behaviour intentional result of new c++11 feature, namely user-defined literals. can insert space before __file__ , qtostring ensure treated separate token , expanded.

qt bugreport here.


Comments