Elsewhere (here on SO, for example) and even my own memory tells me that #error
will cause compilation to terminate, but if I compile this:
#ifndef FOO
# error "FOO not defined."
#endif
int main() {
return "exit now!!";
}
I get:
g++ -Wall -o /dev/null main.cpp
main.cpp:2:4: error: #error "FOO not defined."
# error "FOO not defined."
^~~~~
main.cpp: In function 'int main()':
main.cpp:8:10: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
return "exit!!";
^~~~~~~~
This is for g++ versions 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4 20160609) and 7.0.0 (built myself 20161128). (There is a similar question asked here about MS Visual Studio 2015.)
According to the GNU CPP manual:
The directive ‘#error’ causes the preprocessor to report a fatal error. The tokens forming the rest of the line following ‘#error’ are used as the error message.
So, perhaps I just don't know what a "fatal error" is. The gcc option -Wfatal-errors
would imply that a fatal error is one that would cause compilation to terminate, but nothing in the manuals ever defines it (unless I missed it). An answer to this question, however, is a bit more guarded and says that:
[#error] renders the translation unit ill-formed (i.e., it causes compilation to fail)
which I don't read as saying the same thing as saying compilation terminates at that point.
So, is this behaviour of gcc correct?