From 0c86a39db2888ddd17b21d0822b0907e4661d8b6 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 17 Jul 2018 20:10:57 +0200 Subject: [PATCH] lex.c (_cpp_lex_direct): Use CPP_DL_NOTE instead of CPP_DL_PEDWARN... * lex.c (_cpp_lex_direct): Use CPP_DL_NOTE instead of CPP_DL_PEDWARN, CPP_DL_WARNING or CPP_DL_ERROR for note that diagnostics for C++ style comments is reported only once per file and guard those calls on the preceding cpp_error returning true. * gcc.dg/cpp/pr61854-c90.c (foo): Expect a note, rather than error. * gcc.dg/cpp/pr61854-c94.c (foo): Likewise. * gcc.dg/cpp/pr61854-4.c (foo): Likewise. * gcc.dg/cpp/pr61854-8.c: New test. From-SVN: r262832 --- gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/gcc.dg/cpp/pr61854-4.c | 2 +- gcc/testsuite/gcc.dg/cpp/pr61854-8.c | 12 ++++++++++++ gcc/testsuite/gcc.dg/cpp/pr61854-c90.c | 2 +- gcc/testsuite/gcc.dg/cpp/pr61854-c94.c | 2 +- libcpp/ChangeLog | 8 ++++++++ libcpp/lex.c | 27 +++++++++++++------------- 7 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/cpp/pr61854-8.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 201903959ca..11936ee4610 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2018-07-17 Jakub Jelinek + + * gcc.dg/cpp/pr61854-c90.c (foo): Expect a note, rather than error. + * gcc.dg/cpp/pr61854-c94.c (foo): Likewise. + * gcc.dg/cpp/pr61854-4.c (foo): Likewise. + * gcc.dg/cpp/pr61854-8.c: New test. + 2018-07-17 David Edelsohn * gcc.target/powerpc/pr85456.c: Require longdouble128. diff --git a/gcc/testsuite/gcc.dg/cpp/pr61854-4.c b/gcc/testsuite/gcc.dg/cpp/pr61854-4.c index 5cfa5a74923..3533ae04df9 100644 --- a/gcc/testsuite/gcc.dg/cpp/pr61854-4.c +++ b/gcc/testsuite/gcc.dg/cpp/pr61854-4.c @@ -12,5 +12,5 @@ foo (void) // But error here. #endif /* { dg-error "C\\+\\+ style comments are not allowed in ISO C90" "comments" { target *-*-*} 12 } */ - /* { dg-error "reported only once" "" { target *-*-*} 12 } */ + /* { dg-message "note: \[^\n\r]*reported only once" "" { target *-*-*} 12 } */ } diff --git a/gcc/testsuite/gcc.dg/cpp/pr61854-8.c b/gcc/testsuite/gcc.dg/cpp/pr61854-8.c new file mode 100644 index 00000000000..307513caf4a --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/pr61854-8.c @@ -0,0 +1,12 @@ +/* PR c/61854 */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu89 -pedantic -w" } */ + +int +main (void) +{ + // Comment. + /* { dg-bogus "C\\+\\+ style comments are not allowed in ISO C90" "comments" { target *-*-*} .-1 } */ + /* { dg-bogus "note: \[^\n\r]*reported only once" "" { target *-*-*} .-2 } */ + return 0; +} diff --git a/gcc/testsuite/gcc.dg/cpp/pr61854-c90.c b/gcc/testsuite/gcc.dg/cpp/pr61854-c90.c index d7a9ba5849d..907e975668e 100644 --- a/gcc/testsuite/gcc.dg/cpp/pr61854-c90.c +++ b/gcc/testsuite/gcc.dg/cpp/pr61854-c90.c @@ -7,7 +7,7 @@ foo (void) { // 1st /* { dg-error "C\\+\\+ style comments are not allowed in ISO C90" "comments" { target *-*-*} .-1 } */ - /* { dg-error "reported only once" "" { target *-*-*} .-2 } */ + /* { dg-message "note: \[^\n\r]*reported only once" "" { target *-*-*} .-2 } */ // 2nd // 3rd } diff --git a/gcc/testsuite/gcc.dg/cpp/pr61854-c94.c b/gcc/testsuite/gcc.dg/cpp/pr61854-c94.c index bd5ea6e2389..a8c301d406c 100644 --- a/gcc/testsuite/gcc.dg/cpp/pr61854-c94.c +++ b/gcc/testsuite/gcc.dg/cpp/pr61854-c94.c @@ -7,7 +7,7 @@ foo (void) { // 1st /* { dg-error "C\\+\\+ style comments are not allowed in ISO C90" "comments" { target *-*-*} .-1 } */ - /* { dg-error "reported only once" "" { target *-*-*} .-2 } */ + /* { dg-message "note: \[^\n\r]*reported only once" "" { target *-*-*} .-2 } */ // 2nd // 3rd } diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 7412800afc7..3fef9c957cf 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,11 @@ +2018-07-17 Jason Franklin + Jakub Jelinek + + * lex.c (_cpp_lex_direct): Use CPP_DL_NOTE instead of CPP_DL_PEDWARN, + CPP_DL_WARNING or CPP_DL_ERROR for note that diagnostics for C++ style + comments is reported only once per file and guard those calls on the + preceding cpp_error returning true. + 2018-07-03 Nathan Sidwell Reorg line_map data structures for better packing. diff --git a/libcpp/lex.c b/libcpp/lex.c index 37c365a3560..a2592e045d2 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -2872,10 +2872,10 @@ _cpp_lex_direct (cpp_reader *pfile) && CPP_PEDANTIC (pfile) && ! buffer->warned_cplusplus_comments) { - cpp_error (pfile, CPP_DL_PEDWARN, - "C++ style comments are not allowed in ISO C90"); - cpp_error (pfile, CPP_DL_PEDWARN, - "(this will be reported only once per input file)"); + if (cpp_error (pfile, CPP_DL_PEDWARN, + "C++ style comments are not allowed in ISO C90")) + cpp_error (pfile, CPP_DL_NOTE, + "(this will be reported only once per input file)"); buffer->warned_cplusplus_comments = 1; } /* Or if specifically desired via -Wc90-c99-compat. */ @@ -2883,10 +2883,10 @@ _cpp_lex_direct (cpp_reader *pfile) && ! CPP_OPTION (pfile, cplusplus) && ! buffer->warned_cplusplus_comments) { - cpp_error (pfile, CPP_DL_WARNING, - "C++ style comments are incompatible with C90"); - cpp_error (pfile, CPP_DL_WARNING, - "(this will be reported only once per input file)"); + if (cpp_error (pfile, CPP_DL_WARNING, + "C++ style comments are incompatible with C90")) + cpp_error (pfile, CPP_DL_NOTE, + "(this will be reported only once per input file)"); buffer->warned_cplusplus_comments = 1; } /* In C89/C94, C++ style comments are forbidden. */ @@ -2906,11 +2906,12 @@ _cpp_lex_direct (cpp_reader *pfile) } else if (! buffer->warned_cplusplus_comments) { - cpp_error (pfile, CPP_DL_ERROR, - "C++ style comments are not allowed in ISO C90"); - cpp_error (pfile, CPP_DL_ERROR, - "(this will be reported only once per input " - "file)"); + if (cpp_error (pfile, CPP_DL_ERROR, + "C++ style comments are not allowed in " + "ISO C90")) + cpp_error (pfile, CPP_DL_NOTE, + "(this will be reported only once per input " + "file)"); buffer->warned_cplusplus_comments = 1; } } -- 2.30.2