diff mbox series

[C++] Another permerror related tweak

Message ID 4c47d535-ce39-1a2b-6d62-1fde456b12d2@oracle.com
State New
Headers show
Series [C++] Another permerror related tweak | expand

Commit Message

Paolo Carlini July 17, 2018, 12:17 p.m. UTC
Hi again,

here I noticed a pair of consecutive permerrors (instead of permerror + 
inform) and also that the first one isn't exploiting 
DECL_SOURCE_LOCATION (which makes a real difference at least in a couple 
of cases which I'm explicitly testing below). Tested x86_64-linux.

Thanks, Paolo.

/////////////////
/cp
2018-07-17  Paolo Carlini  <paolo.carlini@oracle.com>

	* class.c (note_name_declared_in_class): Prefer permerror + inform
	to a pair of permerrors; use DECL_SOURCE_LOCATION.

/testsuite
2018-07-17  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/ext/uow-3.C: Adjust.
	* g++.dg/ext/uow-4.C: Likewise.
	* g++.dg/lookup/name-clash11.C: Likewise.
	* g++.dg/lookup/name-clash7.C: Likewise.
	* g++.dg/lookup/redecl1.C: Likewise.
	* g++.dg/warn/changes-meaning.C: Likewise.
	* g++.old-deja/g++.jason/scoping8.C: Likewise.
	* g++.old-deja/g++.law/nest1.C: Likewise.

Comments

Jason Merrill July 18, 2018, 1:44 a.m. UTC | #1
OK.  And I think this qualifies as obvious; you don't need to wait for
approval on further patches like this.

Jason

On Tue, Jul 17, 2018 at 10:17 PM, Paolo Carlini
<paolo.carlini@oracle.com> wrote:
> Hi again,
>
> here I noticed a pair of consecutive permerrors (instead of permerror +
> inform) and also that the first one isn't exploiting DECL_SOURCE_LOCATION
> (which makes a real difference at least in a couple of cases which I'm
> explicitly testing below). Tested x86_64-linux.
>
> Thanks, Paolo.
>
> /////////////////
>
diff mbox series

Patch

Index: cp/class.c
===================================================================
--- cp/class.c	(revision 262803)
+++ cp/class.c	(working copy)
@@ -8285,10 +8285,12 @@  note_name_declared_in_class (tree name, tree decl)
 	 A name N used in a class S shall refer to the same declaration
 	 in its context and when re-evaluated in the completed scope of
 	 S.  */
-      permerror (input_location, "declaration of %q#D", decl);
-      permerror (location_of ((tree) n->value),
-		 "changes meaning of %qD from %q#D",
-		 OVL_NAME (decl), (tree) n->value);
+      if (permerror (DECL_SOURCE_LOCATION (decl),
+		     "declaration of %q#D changes meaning of %qD",
+		     decl, OVL_NAME (decl)))
+	inform (location_of ((tree) n->value),
+		"%qD declared here as %q#D",
+		OVL_NAME (decl), (tree) n->value);
     }
 }
 
Index: testsuite/g++.dg/ext/uow-3.C
===================================================================
--- testsuite/g++.dg/ext/uow-3.C	(revision 262803)
+++ testsuite/g++.dg/ext/uow-3.C	(working copy)
@@ -1,8 +1,8 @@ 
 /* { dg-do compile } */
 /* { dg-options "-Wall" } */
 
-typedef int UOW;  /* { dg-error "" } */
+typedef int UOW;  /* { dg-message "declared here" } */
 struct ABC {
-  UOW UOW; /* { dg-error "" } */
+  UOW UOW; /* { dg-error "changes meaning" } */
 };
 
Index: testsuite/g++.dg/ext/uow-4.C
===================================================================
--- testsuite/g++.dg/ext/uow-4.C	(revision 262803)
+++ testsuite/g++.dg/ext/uow-4.C	(working copy)
@@ -3,9 +3,9 @@ 
 
 extern "C" {
 
-typedef int UOW;  /* { dg-error "" } */
+typedef int UOW;  /* { dg-message "declared here" } */
 struct ABC {
-  UOW UOW; /* { dg-error "" } */
+  UOW UOW; /* { dg-error "changes meaning" } */
 };
 
 }
Index: testsuite/g++.dg/lookup/name-clash11.C
===================================================================
--- testsuite/g++.dg/lookup/name-clash11.C	(revision 262803)
+++ testsuite/g++.dg/lookup/name-clash11.C	(working copy)
@@ -13,11 +13,11 @@ 
 
 void test_bitset ()
 {
-  int x;                        // { dg-warning "changes meaning" }
+  int x;                        // { dg-message "declared here" }
 
   {
     struct S {
-      int x: sizeof x;          // { dg-warning "declaration" }
+      int x: sizeof x;          // { dg-warning "changes meaning" }
     };
   }
 }
@@ -25,11 +25,11 @@  void test_bitset ()
 void test_enum ()
 {
   // Also exercise (not covered by c++/69023):
-  int y;                        // { dg-warning "changes meaning" }
+  int y;                        // { dg-message "declared here" }
   {
     struct S {
       enum E {
-        y = sizeof y            // { dg-warning "declaration" }
+        y = sizeof y            // { dg-warning "9:declaration of .y. changes meaning" }
       };
 
       // Verify the enumerator has the correct value.
@@ -40,7 +40,7 @@  void test_enum ()
 
 void test_alignas ()
 {
-  enum { A = 16 };              // { dg-warning "changes meaning" }
+  enum { A = 16 };              // { dg-message "declared here" }
   {
     struct S {
 #if __cplusplus >= 201103L
@@ -48,7 +48,7 @@  void test_alignas ()
 #else
       __attribute__ ((aligned (A)))
 #endif
-      int A;                    // { dg-warning "declaration" }
+      int A;                    // { dg-warning "changes meaning" }
 
       // Verify the member has the correct alignment.
       void test () { ASSERT (__alignof__ (this->A) == 16); }
@@ -58,10 +58,10 @@  void test_alignas ()
 
 void test_array ()
 {
-  enum { A = 16 };              // { dg-warning "changes meaning" }
+  enum { A = 16 };              // { dg-message "declared here" }
   {
     struct S {
-      int A [A];                // { dg-warning "declaration" }
+      int A [A];                // { dg-warning "changes meaning" }
 
       // Verify the member has the correct alignment.
       void test () { ASSERT (sizeof (this->A) == 16 * sizeof (int)); }
@@ -71,10 +71,10 @@  void test_array ()
 
 void test_vector ()
 {
-  enum { A = 16 };              // { dg-warning "changes meaning" }
+  enum { A = 16 };              // { dg-message "declared here" }
   {
     struct S {
-      int A __attribute__ ((vector_size (A))); // { dg-warning "declaration" }
+      int A __attribute__ ((vector_size (A))); // { dg-warning "changes meaning" }
 
       // Verify the member has the correct size.
       void test () { ASSERT (sizeof (this->A) == 16); }
Index: testsuite/g++.dg/lookup/name-clash7.C
===================================================================
--- testsuite/g++.dg/lookup/name-clash7.C	(revision 262803)
+++ testsuite/g++.dg/lookup/name-clash7.C	(working copy)
@@ -1,6 +1,6 @@ 
 // PR c++/28513
 
-class foo {			// { dg-error "changes meaning" }
+class foo {			// { dg-message "declared here" }
 public:
   typedef int bar;
 };
@@ -7,5 +7,5 @@ 
 
 class baz {
 public:
-  foo::bar foo;			// { dg-error "declaration" }
+  foo::bar foo;			// { dg-error "changes meaning" }
 };
Index: testsuite/g++.dg/lookup/redecl1.C
===================================================================
--- testsuite/g++.dg/lookup/redecl1.C	(revision 262803)
+++ testsuite/g++.dg/lookup/redecl1.C	(working copy)
@@ -1,7 +1,7 @@ 
 // PR c++/14668
 
-class A {}; // { dg-error "" }
+class A {}; // { dg-message "declared here" }
 class B { 
-  static A *A; // { dg-error "" }
+  static A *A; // { dg-error "changes meaning" }
 }; 
 A *B::A = 0;
Index: testsuite/g++.dg/warn/changes-meaning.C
===================================================================
--- testsuite/g++.dg/warn/changes-meaning.C	(revision 262803)
+++ testsuite/g++.dg/warn/changes-meaning.C	(working copy)
@@ -1,11 +1,11 @@ 
 /* { dg-do compile } */
 /* { dg-options "-fpermissive" } */
 
-template <class _Tp> class auto_ptr {};  /* { dg-warning "changes meaning" } */
+template <class _Tp> class auto_ptr {};  /* { dg-message "declared here" } */
 template <class _Tp>
 class counted_ptr
 {
 public:
-  auto_ptr<_Tp> auto_ptr(); /* { dg-warning "" } */
+  auto_ptr<_Tp> auto_ptr(); /* { dg-warning "17:declaration of .auto_ptr\\<_Tp\\>" } */
 };
 
Index: testsuite/g++.old-deja/g++.jason/scoping8.C
===================================================================
--- testsuite/g++.old-deja/g++.jason/scoping8.C	(revision 262803)
+++ testsuite/g++.old-deja/g++.jason/scoping8.C	(working copy)
@@ -1,8 +1,8 @@ 
 // { dg-do assemble  }
 // Bug: g++ allows two different meanings of a name in the same scope.
 
-typedef int foo;		// { dg-error "" } 
+typedef int foo;		// { dg-message "declared here" }
 struct A {
   A (foo);
-  int foo ();			// { dg-error "" } foo already used in scope
+  int foo ();			// { dg-error "changes meaning" }
 };
Index: testsuite/g++.old-deja/g++.law/nest1.C
===================================================================
--- testsuite/g++.old-deja/g++.law/nest1.C	(revision 262803)
+++ testsuite/g++.old-deja/g++.law/nest1.C	(working copy)
@@ -6,10 +6,10 @@ 
 // Subject:  Local type names bug in g++ 2.3.3
 // Message-ID: <1992Dec30.203807.17504@murdoch.acc.Virginia.EDU>
 
-typedef char* T; // { dg-error "" } previous declaration
+typedef char* T; // { dg-message "declared here" }
 
 struct Y {
     T a;
-    typedef long T; // error. See ARM p189-191 for details// { dg-error "" } 
+    typedef long T; // { dg-error "changes meaning" } 
     T b;
 };