GCC 4.3 related build problems: pedantic preprocessor warnings in C++
Update: This change has been reverted from 4.3 again and won't be in the final release of 4.3.
GCC 4.3 changed pedantic preprocessor warnings in C++ code into errors, in line with the C++ front-end. Because of this change, preprocessor warnings are now errors.
This change has caused at least the twofollowing errors which are all fairly common:
It's not allowed to #define something twice, as in this example:
#define TEST "foo" #define TEST "bar"
This code will lead to the following error:
test2.cc:2:1: error: "TEST" redefined test2.cc:1:1: error: this is the location of the previous definition
Most typically, this occurs because something is defined in a header that is included and then redefined in the current source file. It can also happen when a #define is put in the code but also on the command line, e.g. via -DTEST="bar". This will lead to:
test2.cc:1:1: error: "TEST" redefined <command line>:1:1: error: this is the location of the previous definition
The correct solution is to avoid redefinitions directly or to use #ifndef to make sure that something has not been defined already.
While an #ifdef obviously needs a second parameter, it's not allowed to give one to #else and #endif. Unfortunately, this is commonly done as a reminder for what is being tested for:
#ifdef TEST #endif TEST
This code will lead to the following error:
test3.cc:2:8: error: extra tokens at end of #endif directive