scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 983e4cd19bb2cae781d84d6e75143f9a76935536
parent 60560f4989f5e451ab2d1ad96bc6ebcab6337017
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 22 Jun 2016 11:18:47 +0200

[cc1] Do not allow comments between different files

C89 says: 'A source file shall not end in a partial
preprocessing token or comment', and C99 says:
Must a comment be contained within one #include file? (Yes.).
In the case of C99, otherwise is an UB. We think the best
option here is giving an error.

Diffstat:
Mcc1/lex.c | 13+++++++------
Mcc1/tests/test063.c | 2+-
2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/cc1/lex.c b/cc1/lex.c @@ -167,16 +167,17 @@ comment(int type) repeat: do { if (!c) - delinput(); + goto unterminated; } while (!eof && (c = readchar()) != type); - if (eof) { - errorp("unterminated comment"); - return; - } - + if (eof) + goto unterminated; if (type == '*' && (c = readchar()) != '/') goto repeat; + return; + +unterminated: + errorp("unterminated comment"); } static int diff --git a/cc1/tests/test063.c b/cc1/tests/test063.c @@ -4,7 +4,7 @@ name: TEST063 description: Test a comment that goes beyond of the end of an included file error: -test063.c:12: error: unterminated comment +test063.h:9: error: unterminated comment test063.c:12: error: #endif expected output: */