Antoine Leca
2013-02-22 15:56:14 UTC
Module Name: pcc
Committed By: plunky
Date: Wed Oct 31 12:13:43 UTC 2012
pcc/cc/cpp: token.c
simplify logic in ppdir(), and error() for invalid directive
cvs rdiff -u -r1.97 -r1.98 pcc/cc/cpp/token.c
Last part:Committed By: plunky
Date: Wed Oct 31 12:13:43 UTC 2012
pcc/cc/cpp: token.c
simplify logic in ppdir(), and error() for invalid directive
cvs rdiff -u -r1.97 -r1.98 pcc/cc/cpp/token.c
-out: while ((ch = inch()) != '\n' && ch != -1)
- ;
- unch('\n');
+out: error("invalid preprocessor directive");
}
This change causes the behaviour on garbage after # to change,
from being silently ignored to forcing a warning.
At the very least, the new behaviour have to be optionally disabled: for
reason which are beyond my understanding, a lot of i386 assembler code
out there seem to consider the comment character is not / but #, and
furthermore people expect assembler-with-cpp to deal quietly with such
case; needless to say, the new behaviour breaks such expectation.
A new option to disable the error case could be designed, but I am
asking myself why does it cause a fatal error (error() ends with exit()
in cpp)? It seems to me to be a case for warning(), since it seems easy
to recover from such a case (just using the previous code.)
Also, under the C standard, such a case is a "non-directive" (6.10)
which does not have any defined behaviour in the Standard. So anything
is conforming, from accepting silently to aborting.
I had a look at the behaviour of clang on this case, and found
(PPDirectives.cpp, around lines 585-600) that they handle as special the
case of assembler-with-cpp to no emit the diagnostic and to pass the #
along with the rest of the line, with macros expanded.
Testing suggests GCC is having the same behaviour.
Antoine