public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Neil Booth <neil@daikokuya.co.uk> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, Subject: Re: preprocessor/10613: Please make -Wtrigraphs the default Date: Sun, 04 May 2003 20:06:00 -0000 [thread overview] Message-ID: <20030504200600.18379.qmail@sources.redhat.com> (raw) The following reply was made to PR preprocessor/10613; it has been noted by GNATS. From: Neil Booth <neil@daikokuya.co.uk> To: Hallvard B Furuseth <h.b.furuseth@usit.uio.no> Cc: gcc-gnats@gcc.gnu.org, gcc-patches@gcc.gnu.org, Zack Weinberg <zack@codesourcery.com> Subject: Re: preprocessor/10613: Please make -Wtrigraphs the default Date: Sun, 4 May 2003 21:00:17 +0100 This is a patch for preprocessor/10613 and preprocessor/10614. We warn about trigraphs, unless an explicit -trigraphs (or -std implying -trigraphs) is given. -Wall still implies -Wtrigraphs. Further, we want about trigraphs that imply an escaped newline sequence in a comment, but no other trigraphs in a comment are warned about. This is a good enough approximation to the "warn about a trigraph iff it changes the meaning of the program" rule. Tests included. Tested on NetBSD-x86. Neil. * 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. Index: cppinit.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v retrieving revision 1.276 diff -u -p -r1.276 cppinit.c --- cppinit.c 19 Apr 2003 00:22:48 -0000 1.276 +++ cppinit.c 4 May 2003 19:56:49 -0000 @@ -149,6 +149,7 @@ cpp_create_reader (lang, table) CPP_OPTION (pfile, show_column) = 1; CPP_OPTION (pfile, tabstop) = 8; CPP_OPTION (pfile, operator_names) = 1; + CPP_OPTION (pfile, warn_trigraphs) = 2; CPP_OPTION (pfile, warn_endif_labels) = 1; CPP_OPTION (pfile, warn_deprecated) = 1; CPP_OPTION (pfile, warn_long_long) = !CPP_OPTION (pfile, c99); @@ -553,6 +554,9 @@ post_options (pfile) pfile->state.prevent_expansion = 1; CPP_OPTION (pfile, traditional) = 0; } + + if (CPP_OPTION (pfile, warn_trigraphs) == 2) + CPP_OPTION (pfile, warn_trigraphs) = !CPP_OPTION (pfile, trigraphs); if (CPP_OPTION (pfile, traditional)) { Index: cpplex.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/cpplex.c,v retrieving revision 1.233 diff -u -p -r1.233 cpplex.c --- cpplex.c 26 Apr 2003 21:03:51 -0000 1.233 +++ cpplex.c 4 May 2003 19:56:49 -0000 @@ -63,6 +63,7 @@ static void save_comment PARAMS ((cpp_re 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_comme } 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; } Index: testsuite/gcc.dg/cpp/Wtrigraphs-2.c =================================================================== RCS file: testsuite/gcc.dg/cpp/Wtrigraphs-2.c diff -N testsuite/gcc.dg/cpp/Wtrigraphs-2.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gcc.dg/cpp/Wtrigraphs-2.c 4 May 2003 19:56:49 -0000 @@ -0,0 +1,20 @@ +/* { dg-do preprocess } */ +/* { dg-options "-std=c99 -Wtrigraphs -fno-show-column" } */ + +/* Test we don't double warn for trigraphs immediately after preceding + text. Source Neil Booth. 4 May 2003. */ + +/* { dg-bogus "ignored" } Test ??< ??= a few ??/ random things in + { dg-warning "converted" } some ??/ + { dg-bogus "ignored" } ??< comments. */ + +// { dg-bogus "ignored" } More ??/ comment ??> tests. + +// { dg-warning "converted" } Another ??/ + Test + +// { dg-warning "converted" } And another with space after ??/ + the escape + +// { dg-bogus "ignored" } A tricky one ??/\ + Index: testsuite/gcc.dg/cpp/Wtrigraphs.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/cpp/Wtrigraphs.c,v retrieving revision 1.1 diff -u -p -r1.1 Wtrigraphs.c --- testsuite/gcc.dg/cpp/Wtrigraphs.c 22 Nov 2000 20:37:44 -0000 1.1 +++ testsuite/gcc.dg/cpp/Wtrigraphs.c 4 May 2003 19:56:49 -0000 @@ -1,5 +1,5 @@ /* { dg-do preprocess } */ -/* { dg-options "-Wtrigraphs -fno-show-column" } */ +/* { dg-options "-std=gnu99 -Wtrigraphs -fno-show-column" } */ /* Test we don't double warn for trigraphs immediately after preceding text. Source Neil Booth. 22 Nov 2000. */ @@ -7,3 +7,21 @@ abcdef??< /* { dg-warning "ignored" } */ 123456??> /* { dg-warning "ignored" } */ +??= /* { dg-warning "ignored" } */ + +/* Test we warn of escaped newlines only in comments. Source Neil + Booth. 4 May 2003. */ + +/* { dg-bogus "ignored" } Test ??< ??= a few ??/ random things in + { dg-warning "ignored" } some ??/ + { dg-bogus "ignored" } ??< comments. */ + +// { dg-bogus "ignored" } More ??/ comment ??> tests. + +// { dg-warning "ignored" } Another ??/ + Test + +// { dg-warning "ignored" } And another with space after ??/ + the escape + +// { dg-bogus "ignored" } A tricky one ??/\ + Index: doc/cpp.texi =================================================================== RCS file: /cvs/gcc/gcc/gcc/doc/cpp.texi,v retrieving revision 1.54 diff -u -p -r1.54 cpp.texi --- doc/cpp.texi 12 Mar 2003 20:30:05 -0000 1.54 +++ doc/cpp.texi 4 May 2003 19:56:51 -0000 @@ -293,16 +293,18 @@ obsolete systems that lack some of C's p example, @samp{??/} stands for @samp{\}, so @t{'??/n'} is a character constant for a newline. -Trigraphs are not popular and many compilers implement them incorrectly. -Portable code should not rely on trigraphs being either converted or -ignored. If you use the @option{-Wall} or @option{-Wtrigraphs} options, -GCC will warn you when a trigraph would change the meaning of your -program if it were converted. +Trigraphs are not popular and many compilers implement them +incorrectly. Portable code should not rely on trigraphs being either +converted or ignored. With @option{-Wtrigraphs} GCC will warn you +when a trigraph may change the meaning of your program if it were +converted. @xref{Wtrigraphs}. -In a string constant, you can prevent a sequence of question marks from -being confused with a trigraph by inserting a backslash between the -question marks. @t{"(??\?)"} is the string @samp{(???)}, not -@samp{(?]}. Traditional C compilers do not recognize this idiom. +In a string constant, you can prevent a sequence of question marks +from being confused with a trigraph by inserting a backslash between +the question marks, or by separating the string literal at the +trigraph and making use of string literal concatenation. @t{"(??\?)"} +is the string @samp{(???)}, not @samp{(?]}. Traditional C compilers +do not recognize these idioms. The nine trigraphs and their replacements are Index: doc/cppopts.texi =================================================================== RCS file: /cvs/gcc/gcc/gcc/doc/cppopts.texi,v retrieving revision 1.18 diff -u -p -r1.18 cppopts.texi --- doc/cppopts.texi 16 Mar 2003 10:37:06 -0000 1.18 +++ doc/cppopts.texi 4 May 2003 19:56:51 -0000 @@ -69,10 +69,12 @@ use @option{-o} to specify the output fi @item -Wall @opindex Wall -Turns on all optional warnings which are desirable for normal code. At -present this is @option{-Wcomment} and @option{-Wtrigraphs}. Note that -many of the preprocessor's warnings are on by default and have no -options to control them. +Turns on all optional warnings which are desirable for normal code. +At present this is @option{-Wcomment}, @option{-Wtrigraphs}, +@option{-Wmultichar} and a warning about integer promotion causing a +change of sign in @code{#if} expressions. Note that many of the +preprocessor's warnings are on by default and have no options to +control them. @item -Wcomment @itemx -Wcomments @@ -84,10 +86,13 @@ comment, or whenever a backslash-newline @item -Wtrigraphs @opindex Wtrigraphs -Warn if any trigraphs are encountered. This option used to take effect -only if @option{-trigraphs} was also specified, but now works -independently. Warnings are not given for trigraphs within comments, as -they do not affect the meaning of the program. +@anchor{Wtrigraphs} +Warn if any trigraphs that may change the meaning of a program are +encountered. This option is in effect unless trigraphs are turned on, +and is implied by @option{-Wall}. With the exception of a trigraph +that would form an escaped newline, warnings are not given for +trigraphs within comments as they do not affect the meaning of the +program. @item -Wtraditional @opindex Wtraditional
next reply other threads:[~2003-05-04 20:06 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2003-05-04 20:06 Neil Booth [this message] -- strict thread matches above, loose matches on Subject: below -- 2003-05-04 21:36 Neil Booth 2003-05-04 20:56 Zack Weinberg 2003-05-04 20:05 neil 2003-05-04 10:06 Hallvard B Furuseth 2003-05-04 10:06 Neil Booth 2003-05-04 9:40 neil 2003-05-04 1:16 Zack Weinberg 2003-05-03 23:26 Neil Booth 2003-05-03 23:16 Hallvard B Furuseth
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20030504200600.18379.qmail@sources.redhat.com \ --to=neil@daikokuya.co.uk \ --cc=gcc-prs@gcc.gnu.org \ --cc=nobody@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).