aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2009-02-21 21:25:39 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2009-02-21 21:25:39 +0000
commit4bb09c26bc590129675100ee0a87f9408b8afab9 (patch)
tree7886f1b6dbd2bde455eb82ab0f653f93286218f7
parent8e361f234b4c853d77a8a8146d093b13ce005ce2 (diff)
downloadgcc-4bb09c26bc590129675100ee0a87f9408b8afab9.zip
gcc-4bb09c26bc590129675100ee0a87f9408b8afab9.tar.gz
gcc-4bb09c26bc590129675100ee0a87f9408b8afab9.tar.bz2
lex.c (lex_string): Return a CPP_LESS token for missing '>' in a header name.
libcpp: * lex.c (lex_string): Return a CPP_LESS token for missing '>' in a header name. (_cpp_lex_direct): Handle this. gcc/testsuite: * gcc.dg/cpp/include4.c: New test. From-SVN: r144361
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/include4.c14
-rw-r--r--libcpp/ChangeLog6
-rw-r--r--libcpp/lex.c15
4 files changed, 37 insertions, 2 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 160b9f6..1d2db2e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2009-02-21 Joseph Myers <joseph@codesourcery.com>
+
+ * gcc.dg/cpp/include4.c: New test.
+
2008-02-21 Uros Bizjak <ubizjak@gmail.com>
PR target/39256
diff --git a/gcc/testsuite/gcc.dg/cpp/include4.c b/gcc/testsuite/gcc.dg/cpp/include4.c
new file mode 100644
index 0000000..d5e7fee
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/include4.c
@@ -0,0 +1,14 @@
+/* Preprocessing tokens are always formed according to a greedy algorithm,
+ so "#include <stddef.h" must be interpreted as a sequence of tokens,
+ of which the "h" then gets macro expanded. Likewise the other
+ examples. */
+
+#define h h>
+#include <stddef.h
+#undef h
+
+#define foo stddef.h>
+#include <foo
+
+#include <foo /*
+> */
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index f84aab3..d86092b 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,9 @@
+2009-02-21 Joseph Myers <joseph@codesourcery.com>
+
+ * lex.c (lex_string): Return a CPP_LESS token for missing '>' in a
+ header name.
+ (_cpp_lex_direct): Handle this.
+
2009-02-15 Richard Guenther <rguenther@suse.de>
Revert last change.
diff --git a/libcpp/lex.c b/libcpp/lex.c
index 96d1a99..452e8ea 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -613,7 +613,9 @@ create_literal (cpp_reader *pfile, cpp_token *token, const uchar *base,
/* Lexes a string, character constant, or angle-bracketed header file
name. The stored string contains the spelling, including opening
quote and leading any leading 'L', 'u' or 'U'. It returns the type
- of the literal, or CPP_OTHER if it was not properly terminated.
+ of the literal, or CPP_OTHER if it was not properly terminated, or
+ CPP_LESS for an unterminated header name which must be relexed as
+ normal tokens.
The spelling is NUL-terminated, but it is not guaranteed that this
is the first NUL since embedded NULs are preserved. */
@@ -652,6 +654,14 @@ lex_string (cpp_reader *pfile, cpp_token *token, const uchar *base)
else if (c == '\n')
{
cur--;
+ /* Unmatched quotes always yield undefined behavior, but
+ greedy lexing means that what appears to be an unterminated
+ header name may actually be a legitimate sequence of tokens. */
+ if (terminator == '>')
+ {
+ token->type = CPP_LESS;
+ return;
+ }
type = CPP_OTHER;
break;
}
@@ -1181,7 +1191,8 @@ _cpp_lex_direct (cpp_reader *pfile)
if (pfile->state.angled_headers)
{
lex_string (pfile, result, buffer->cur - 1);
- break;
+ if (result->type != CPP_LESS)
+ break;
}
result->type = CPP_LESS;