commit 983e4cd19bb2cae781d84d6e75143f9a76935536
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Wed Jun 22 11:18:47 2016 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Wed Jun 22 11:18:47 2016 +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.

diff --git a/cc1/lex.c b/cc1/lex.c
index 6f89352..7f4a6f8 100644
--- 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
index b4d7f28..1082f49 100644
--- 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:
 */

Reply via email to