diff options
author | Neil Booth <neil@gcc.gnu.org> | 2003-05-04 20:03:55 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2003-05-04 20:03:55 +0000 |
commit | a8eb6044a9468a56cab63890820e17101ce8fd64 (patch) | |
tree | db0e598a611fbe90ebcaf267b9665fd02c67a70f /gcc/cpplex.c | |
parent | 09780dfb652960d422da1c5a9d81dc536cdf09f4 (diff) | |
download | gcc-a8eb6044a9468a56cab63890820e17101ce8fd64.zip gcc-a8eb6044a9468a56cab63890820e17101ce8fd64.tar.gz gcc-a8eb6044a9468a56cab63890820e17101ce8fd64.tar.bz2 |
cppinit.c (cpp_create_reader, [...]): Warn about trigraphs unless explicity set or -trigraphs.
* cppinit.c (cpp_create_reader, post_options): Warn about
trigraphs unless explicity set or -trigraphs.
* cpplex.c (warn_in_comment): New.
(_cpp_process_line_notes): Better handling of -Wtrigraphs.
(_cpp_skip_block_comment): Add call to _cpp_process_line_notes.
* doc/cppopts.texi, doc/cpp.texi: Update.
testsuite:
* gcc.dg/cpp/Wtrigraphs.c: Update.
* gcc.dg/cpp/Wtrigraphs-2.c: New tests.
From-SVN: r66459
Diffstat (limited to 'gcc/cpplex.c')
-rw-r--r-- | gcc/cpplex.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/gcc/cpplex.c b/gcc/cpplex.c index 4f0767e..5f3e3f6 100644 --- a/gcc/cpplex.c +++ b/gcc/cpplex.c @@ -63,6 +63,7 @@ static void save_comment PARAMS ((cpp_reader *, cpp_token *, const uchar *, cppchar_t)); static void create_literal PARAMS ((cpp_reader *, cpp_token *, const uchar *, unsigned int, enum cpp_ttype)); +static bool warn_in_comment PARAMS ((cpp_reader *, _cpp_line_note *)); static int name_p PARAMS ((cpp_reader *, const cpp_string *)); static cppchar_t maybe_read_ucn PARAMS ((cpp_reader *, const uchar **)); static tokenrun *next_tokenrun PARAMS ((tokenrun *)); @@ -180,6 +181,36 @@ _cpp_clean_line (pfile) buffer->next_line = s + 1; } +/* Return true if the trigraph indicated by NOTE should be warned + about in a comment. */ +static bool +warn_in_comment (pfile, note) + cpp_reader *pfile; + _cpp_line_note *note; +{ + const uchar *p; + + /* Within comments we don't warn about trigraphs, unless the + trigraph forms an escaped newline, as that may change + behaviour. */ + if (note->type != '/') + return false; + + /* If -trigraphs, then this was an escaped newline iff the next note + is coincident. */ + if (CPP_OPTION (pfile, trigraphs)) + return note[1].pos == note->pos; + + /* Otherwise, see if this forms an escaped newline. */ + p = note->pos + 3; + while (is_nvspace (*p)) + p++; + + /* There might have been escaped newlines between the trigraph and the + newline we found. Hence the position test. */ + return (*p == '\n' && p < note[1].pos); +} + /* Process the notes created by add_line_note as far as the current location. */ void @@ -219,7 +250,8 @@ _cpp_process_line_notes (pfile, in_comment) } else if (_cpp_trigraph_map[note->type]) { - if (!in_comment && CPP_OPTION (pfile, warn_trigraphs)) + if (CPP_OPTION (pfile, warn_trigraphs) + && (!in_comment || warn_in_comment (pfile, note))) { if (CPP_OPTION (pfile, trigraphs)) cpp_error_with_line (pfile, DL_WARNING, pfile->line, col, @@ -284,6 +316,7 @@ _cpp_skip_block_comment (pfile) } } + _cpp_process_line_notes (pfile, true); return false; } |