cpplib: Header name syntax
Neil Booth
NeilB@earthling.net
Sat Nov 4 03:11:00 GMT 2000
The parsing of header names is already correct so that the terminating
" or > cannot be escaped. This disallows multiline strings in
#include family directives, and adds a test for all this behaviour.
Neil.
* cpplex.c (parse_string): Don't allow multiline strings in
#include family directives.
* gcc.dg/cpp/include2.c: New tests.
Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpplex.c,v
retrieving revision 1.110
diff -u -p -r1.110 cpplex.c
--- cpplex.c 2000/11/01 07:32:23 1.110
+++ cpplex.c 2000/11/04 11:08:16
@@ -675,8 +675,8 @@ parse_string (pfile, token, terminator)
/* Character constants and header names may not extend over
multiple lines. In Standard C, neither may strings.
Unfortunately, we accept multiline strings as an
- extension. */
- if (terminator != '"')
+ extension, except in #include family directives. */
+ if (terminator != '"' || pfile->state.angled_headers)
{
unterminated (pfile, terminator);
break;
Index: testsuite/gcc.dg/cpp/include2.c
===================================================================
RCS file: include2.c
diff -N include2.c
--- /dev/null Tue May 5 13:32:27 1998
+++ include2.c Sat Nov 4 03:08:24 2000
@@ -0,0 +1,15 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc. */
+
+/* { dg-do preprocess } */
+
+/* Tests that #include does not allow the terminating '>' or '"' to be
+ escaped, as per the standard. */
+
+/* Source: Neil Booth, 4 Nov 2000. */
+
+#include <silly\>> /* { dg-warning "extra tokens" "" } */
+#include "silly\"" /* { dg-error "missing" "" } */
+
+/* { dg-error "No such file" "" { target *-*-* } 10 } */
+/* { dg-error "No such file" "" { target *-*-* } 11 } */
+/* { dg-warning "extra tokens" "" { target *-*-* } 11 } */
More information about the Gcc-patches
mailing list