Fix error level of warning about C++ style comments

Message ID 1531839102.2603788.1443656544.2D77EFD3@webmail.messagingengine.com
State New
Headers show
Series
  • Fix error level of warning about C++ style comments
Related show

Commit Message

Jason Franklin July 17, 2018, 2:51 p.m.
Greetings,

Below is a simple patch for fixing the error level of an additional note
that follows a warning about using C++ style comments.  The ChangeLog
entry is below, followed by the patch.  

Tried to figure out how to run the tests, but not sure if it's necessary for
something so simple...  would appreciate some guidance here.

Let me know if everything looks good.  Thanks!


2018-07-17  Jason Franklin  <j_fra@fastmail.us>

	* libcpp/lex.c: Fix error level for note following warning about
	the use of C++ style comments.


From abd68997bdaf77d48aeb653fab7311b16791d9da Mon Sep 17 00:00:00 2001
From: Jason Franklin <j_fra@fastmail.us>

Date: Tue, 17 Jul 2018 10:47:28 -0400
Subject: [PATCH] Fix error level for note on C++ comment warning

---
 libcpp/lex.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--
2.17.1

Comments

Jakub Jelinek July 17, 2018, 3:07 p.m. | #1
On Tue, Jul 17, 2018 at 07:51:42AM -0700, Jason Franklin wrote:
> Greetings,

> 

> Below is a simple patch for fixing the error level of an additional note

> that follows a warning about using C++ style comments.  The ChangeLog

> entry is below, followed by the patch.  

> 

> Tried to figure out how to run the tests, but not sure if it's necessary for

> something so simple...  would appreciate some guidance here.

> 

> Let me know if everything looks good.  Thanks!

> 

> 

> 2018-07-17  Jason Franklin  <j_fra@fastmail.us>

> 

> 	* libcpp/lex.c: Fix error level for note following warning about

> 	the use of C++ style comments.


The ChangeLog entry for libcpp/ should not include libcpp/ prefix and
should include the function name, so:
	* lex.c (_cpp_lex_direct): Fix ...

> diff --git a/libcpp/lex.c b/libcpp/lex.c

> index 37c365a3560..4b93691bd1e 100644

> --- a/libcpp/lex.c

> +++ b/libcpp/lex.c

> @@ -2874,7 +2874,7 @@ _cpp_lex_direct (cpp_reader *pfile)

>             {

>               cpp_error (pfile, CPP_DL_PEDWARN,

>                          "C++ style comments are not allowed in ISO C90");

> -             cpp_error (pfile, CPP_DL_PEDWARN,

> +             cpp_error (pfile, CPP_DL_NOTE,

>                          "(this will be reported only once per input file)");


This has the undesirable effect that for say:
// foo
int i;

you get with this patch:
gcc -S -pedantic test.c -std=gnu89 -w
test.c:1:1: note: (this will be reported only once per input file)
 // foo
 ^

while before that you'd get no diagnostics at all.

So, instead it should do:
	      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)");
which makes sure the note is emitted only if the warning/error before it is
emitted.

>               buffer->warned_cplusplus_comments = 1;

>             }

> @@ -2885,7 +2885,7 @@ _cpp_lex_direct (cpp_reader *pfile)

>             {

>               cpp_error (pfile, CPP_DL_WARNING,

>                          "C++ style comments are incompatible with C90");

> -             cpp_error (pfile, CPP_DL_WARNING,

> +             cpp_error (pfile, CPP_DL_NOTE,

>                          "(this will be reported only once per input file)");

>               buffer->warned_cplusplus_comments = 1;

>             }


Likewise.  Furthermore, there is
                  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)");
a few lines below, this third spot needs a similar change too.

	Jakub
Jason Franklin July 17, 2018, 3:39 p.m. | #2
Jakub,

Thanks so much for the review!  Below is an updated ChangeLog entry and
patch.


2018-07-17  Jason Franklin  <j_fra@fastmail.us>

	* lex.c (_cpp_lex_direct): Fix error level for note following
	warning about the use of C++ style comments.


From 1380d73031d76be76019e67f203cb7d98fb5ee60 Mon Sep 17 00:00:00 2001
From: Jason Franklin <j_fra@fastmail.us>

Date: Tue, 17 Jul 2018 11:36:39 -0400
Subject: [PATCH] Fix error level of warning about C++ comments

---
 libcpp/lex.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/libcpp/lex.c b/libcpp/lex.c
index 37c365a3560..1bf89b8da7a 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,11 @@ _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.17.1
Jakub Jelinek July 17, 2018, 6:12 p.m. | #3
On Tue, Jul 17, 2018 at 08:39:30AM -0700, Jason Franklin wrote:
> Thanks so much for the review!  Below is an updated ChangeLog entry and

> patch.


Thanks.

I've fixed some formatting issues and testsuite (3 tests started FAILing),
plus added one more test, bootstrapped/regtested on x86_64-linux and
i686-linux and committed to trunk:

2018-07-17  Jason Franklin  <j_fra@fastmail.us>
	    Jakub Jelinek  <jakub@redhat.com>

	* 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.

--- libcpp/lex.c.jj	2018-02-28 18:13:38.118386495 +0100
+++ libcpp/lex.c	2018-07-17 17:43:55.388843136 +0200
@@ -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;
 		}
 	    }
--- gcc/testsuite/gcc.dg/cpp/pr61854-c90.c.jj	2017-04-19 15:46:24.412008934 +0200
+++ gcc/testsuite/gcc.dg/cpp/pr61854-c90.c	2018-07-17 17:50:05.458331441 +0200
@@ -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
 }
--- gcc/testsuite/gcc.dg/cpp/pr61854-c94.c.jj	2017-04-19 15:46:25.265997760 +0200
+++ gcc/testsuite/gcc.dg/cpp/pr61854-c94.c	2018-07-17 17:50:22.670354143 +0200
@@ -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
 }
--- gcc/testsuite/gcc.dg/cpp/pr61854-4.c.jj	2014-09-18 15:48:24.297978857 +0200
+++ gcc/testsuite/gcc.dg/cpp/pr61854-4.c	2018-07-17 17:49:37.289294264 +0200
@@ -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 } */
 }
--- gcc/testsuite/gcc.dg/cpp/pr61854-8.c.jj	2018-07-17 17:52:29.633521672 +0200
+++ gcc/testsuite/gcc.dg/cpp/pr61854-8.c	2018-07-17 17:55:25.475753689 +0200
@@ -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;
+}


	Jakub

Patch

diff --git a/libcpp/lex.c b/libcpp/lex.c
index 37c365a3560..4b93691bd1e 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -2874,7 +2874,7 @@  _cpp_lex_direct (cpp_reader *pfile)
            {
              cpp_error (pfile, CPP_DL_PEDWARN,
                         "C++ style comments are not allowed in ISO C90");
-             cpp_error (pfile, CPP_DL_PEDWARN,
+             cpp_error (pfile, CPP_DL_NOTE,
                         "(this will be reported only once per input file)");
              buffer->warned_cplusplus_comments = 1;
            }
@@ -2885,7 +2885,7 @@  _cpp_lex_direct (cpp_reader *pfile)
            {
              cpp_error (pfile, CPP_DL_WARNING,
                         "C++ style comments are incompatible with C90");
-             cpp_error (pfile, CPP_DL_WARNING,
+             cpp_error (pfile, CPP_DL_NOTE,
                         "(this will be reported only once per input file)");
              buffer->warned_cplusplus_comments = 1;
            }