Ho il problema che quando g ++ viene eseguito in modalità C++ 11, alcune macro del proprocessore non sono espanse corrette. Questo mi crea problemi durante la compilazione di programmi che usano Qt.Comportamento del preprocessore strano g ++ in modalità C++ 11
$ g++ --version
g++ (GCC) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Il seguente tagliò espone il problema:
$ 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 senza C++ 11 fa la cosa giusta.
$ g++ -E foo.cpp
# 1 "foo.cpp"
# 1 "<command-line>"
# 1 "foo.cpp"
# 15 "foo.cpp"
qFlagLocation("0""grml" "\0""foo.cpp"":""15")
Ma in C++ modalità 11 macro il QTOSTRING non viene espansa, causando un errore di compilazione alla linea di source.
$ 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))
Questo comportamento è destinato e cosa posso fare per abilitare l'espansione?
Per la prossima volta: includere sempre gli errori effettivi. – Xeo