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 leads to a number of errors that are in my opinion too strict and I've
started a discussion about this problem on the GCC mailing list. I hope
this change will be reverted, or that some of these errors are downgraded
to warnings again, but users of current
gcc-snapshot package
might encounter these errors. I haven't filed bugs about these issues
since I'm waiting for a census from GCC developers. Nevertheless, it makes
sense to fix these problems if they are present in one's package.
This change has caused at least the three following errors which are all
fairly common.
error: "xxx" redefined
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.
extra tokens at end of #endif directive
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
missing newline
The last line of a source file has to end with a newline. If this is not
the case, the following error is now shown:
test4.cc:1:19: error: no newline at end of file