diff mbox

[C++] Prefer error + inform to two errors in check_template_shadow

Message ID 55A3C015.3070105@oracle.com
State New
Headers show

Commit Message

Paolo Carlini July 13, 2015, 1:41 p.m. UTC
Hi,

while going thru the pending template template issues, I noticed that 
check_template_shadow still emits two errors. I believe we also want to 
simply use D instead of #D for template parameters, that avoids the nit 
about class T vs template T which could be slightly confusing to 
novices, I suppose.

Tested x86_64-linux.

Thanks,
Paolo.

//////////////////////////////
/cp
2015-07-13  Paolo Carlini  <paolo.carlini@oracle.com>

	* pt.c (check_template_shadow): Emit error + inform instead of
	two errors.

/testsuite
2015-07-13  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/template/crash81.C: Adjust for error + inform change.
	* g++.dg/template/pr58878.C: Likewise.
	* g++.dg/template/shadow1.C: Likewise.
	* g++.dg/template/shadow2.C: Likewise.
	* g++.old-deja/g++.benjamin/tem03.C: Likewise.
	* g++.old-deja/g++.benjamin/tem04.C: Likewise.
	* g++.old-deja/g++.brendan/crash7.C: Likewise.
	* g++.old-deja/g++.pt/shadow2.C: Likewise.

Comments

Jason Merrill July 14, 2015, 3:07 p.m. UTC | #1
On 07/13/2015 09:41 AM, Paolo Carlini wrote:
> +++ testsuite/g++.dg/template/crash81.C	(working copy)
> @@ -3,6 +3,6 @@
>   struct A
>   {
>     template<T::X> struct X; // { dg-error "'T' has not been declared" "T" }
> -  // { dg-error "declaration of 'template<int X> struct A::X'" "A::X" { target *-*-* } 5 }
> -  // { dg-error "shadows template parm 'int X'" "shadow" { target *-*-* } 5 }
> +  // { dg-error "declaration of 'template<int X> struct A::X' shadows" "A::X" { target *-*-* } 5 }
> +  // { dg-message "template parameter 'X'" "" { target *-*-* } 5 }

I don't see any reason to check for specific diagnostics here; the 
latter two messages are poor error-recovery, not something to test for.

OK with that change.

Jason
Paolo Carlini July 14, 2015, 3:43 p.m. UTC | #2
Hi,

On 07/14/2015 05:07 PM, Jason Merrill wrote:
> On 07/13/2015 09:41 AM, Paolo Carlini wrote:
>> +++ testsuite/g++.dg/template/crash81.C (working copy)
>> @@ -3,6 +3,6 @@
>>   struct A
>>   {
>>     template<T::X> struct X; // { dg-error "'T' has not been 
>> declared" "T" }
>> -  // { dg-error "declaration of 'template<int X> struct A::X'" 
>> "A::X" { target *-*-* } 5 }
>> -  // { dg-error "shadows template parm 'int X'" "shadow" { target 
>> *-*-* } 5 }
>> +  // { dg-error "declaration of 'template<int X> struct A::X' 
>> shadows" "A::X" { target *-*-* } 5 }
>> +  // { dg-message "template parameter 'X'" "" { target *-*-* } 5 }
>
> I don't see any reason to check for specific diagnostics here; the 
> latter two messages are poor error-recovery, not something to test for.
Indeed, I noticed the error recovery issue, which I didn't know, and 
considered looking into it, when I'm done with some other things. In the 
meanwhile I'm shortening the expected error/inform.

Thanks,
Paolo.
diff mbox

Patch

Index: cp/pt.c
===================================================================
--- cp/pt.c	(revision 225730)
+++ cp/pt.c	(working copy)
@@ -3661,8 +3661,13 @@  check_template_shadow (tree decl)
   if (DECL_SELF_REFERENCE_P (decl))
     return false;
 
-  error ("declaration of %q+#D", decl);
-  error (" shadows template parm %q+#D", olddecl);
+  if (DECL_TEMPLATE_PARM_P (decl))
+    error ("declaration of template parameter %q+D shadows "
+	   "template parameter", decl);
+  else
+    error ("declaration of %q+#D shadows template parameter", decl);
+  inform (DECL_SOURCE_LOCATION (olddecl),
+	  "template parameter %qD declared here", olddecl);
   return false;
 }
 
Index: testsuite/g++.dg/template/crash81.C
===================================================================
--- testsuite/g++.dg/template/crash81.C	(revision 225730)
+++ testsuite/g++.dg/template/crash81.C	(working copy)
@@ -3,6 +3,6 @@ 
 struct A
 {
   template<T::X> struct X; // { dg-error "'T' has not been declared" "T" }
-  // { dg-error "declaration of 'template<int X> struct A::X'" "A::X" { target *-*-* } 5 }
-  // { dg-error "shadows template parm 'int X'" "shadow" { target *-*-* } 5 }
+  // { dg-error "declaration of 'template<int X> struct A::X' shadows" "A::X" { target *-*-* } 5 }
+  // { dg-message "template parameter 'X'" "" { target *-*-* } 5 }
 };
Index: testsuite/g++.dg/template/pr58878.C
===================================================================
--- testsuite/g++.dg/template/pr58878.C	(revision 225730)
+++ testsuite/g++.dg/template/pr58878.C	(working copy)
@@ -3,10 +3,10 @@ 
 // Template-members of non-template class
 struct A
 {
-    template <typename t>    // { dg-error "shadows" }
+    template <typename t>    // { dg-message "template parameter" }
         void f()
         {
-            int t = 1;       // { dg-error "declaration" }
+            int t = 1;       // { dg-error "shadows" }
         }
 
     template <typename t>
@@ -13,39 +13,39 @@  struct A
         void g();
 };
 
-template <typename t>        // { dg-error "shadows" }
+template <typename t>        // { dg-message "template parameter" }
 void A::g()
 {
-    int t = 2;               // { dg-error "declaration" }
+    int t = 2;               // { dg-error "shadows" }
 }
 
 // (Non-template) Members of template class
-template <typename t>        // { dg-error "shadows" }
+template <typename t>        // { dg-message "template parameter" }
 struct B
 {
     void f()
     {
-        int t = 3;           // { dg-error "declaration" }
+        int t = 3;           // { dg-error "shadows" }
     }
 
     void g();
 };
 
-template <typename t>        // { dg-error "shadows" }
+template <typename t>        // { dg-message "template parameter" }
 void B<t>::g()
 {
-    int t = 4;               // { dg-error "declaration" }
+    int t = 4;               // { dg-error "shadows" }
 }
 
 // Template members of template class
-template <typename t>        // { dg-error "shadows" }
+template <typename t>        // { dg-message "template parameter" }
 struct C
 {
-    template <typename s>    // { dg-error "shadows" }
+    template <typename s>    // { dg-message "template parameter" }
     void f()
     {
-        int t = 5;           // { dg-error "declaration" }
-        int s = 6;           // { dg-error "declaration" }
+        int t = 5;           // { dg-error "shadows" }
+        int s = 6;           // { dg-error "shadows" }
     }
 
     template <typename s>
@@ -52,10 +52,10 @@  struct C
     void g();
 };
 
-template <typename t>        // { dg-error "shadows" }
-template <typename s>        // { dg-error "shadows" }
+template <typename t>        // { dg-message "template parameter" }
+template <typename s>        // { dg-message "template parameter" }
 void C<t>::g()
 {
-    int t = 7;               // { dg-error "declaration" }
-    int s = 8;               // { dg-error "declaration" }
+    int t = 7;               // { dg-error "shadows" }
+    int s = 8;               // { dg-error "shadows" }
 }
Index: testsuite/g++.dg/template/shadow1.C
===================================================================
--- testsuite/g++.dg/template/shadow1.C	(revision 225730)
+++ testsuite/g++.dg/template/shadow1.C	(working copy)
@@ -1,4 +1,4 @@ 
 // PR c++/58632
 
-template<template<int I> class A> // { dg-message "shadows" }
-class A {};			// { dg-error "declaration" }
+template<template<int I> class A> // { dg-message "template parameter" }
+class A {};			// { dg-error "shadows" }
Index: testsuite/g++.dg/template/shadow2.C
===================================================================
--- testsuite/g++.dg/template/shadow2.C	(revision 225730)
+++ testsuite/g++.dg/template/shadow2.C	(working copy)
@@ -1,3 +1,3 @@ 
-template <class A, // { dg-error "shadows template parm 'class A'" }
-          template <class A> class B> // { dg-error "declaration of 'class A'" }
+template <class A, // { dg-message "template parameter 'A'" }
+          template <class A> class B> // { dg-error "declaration of template parameter 'A' shadows" }
 class X;
Index: testsuite/g++.old-deja/g++.benjamin/tem03.C
===================================================================
--- testsuite/g++.old-deja/g++.benjamin/tem03.C	(revision 225730)
+++ testsuite/g++.old-deja/g++.benjamin/tem03.C	(working copy)
@@ -18,7 +18,7 @@ 
 
 // 01 
 // declared friend template
-template <class T4>// { dg-error "" } .*
+template <class T4>// { dg-message "" } .*
 class Xone {
 protected:
   T4* next;
@@ -38,7 +38,7 @@  class Xone {
 
 // 02
 // nested template class
-template <class T6>// { dg-error "" } .*
+template <class T6>// { dg-message "" } .*
 class Xtwo {
 protected:
   T6* next;
@@ -58,7 +58,7 @@  class Xtwo {
 
 // 03
 // member templates
-template <class T8>// { dg-error "" } .*
+template <class T8>// { dg-message "" } .*
 class Xthree {
 protected:
   T8* next;
@@ -80,7 +80,7 @@  class Xthree {
 
 // 04
 // local names (14.6.1 p 4)
-template <class T10, int i> struct Xfour {// { dg-error "" } .*
+template <class T10, int i> struct Xfour {// { dg-message "" } .*
   int T10; // { dg-error "" } .*
   void f(){
     char T10; // { dg-error "declaration of 'char T10'" }
@@ -94,7 +94,7 @@  template <class T12, int i> struct Xfive {
   void f();
 };
 
-template <class T13, int i> void Xfive<T13,i>::f() {// { dg-error "" } .*
+template <class T13, int i> void Xfive<T13,i>::f() {// { dg-message "" } .*
   int T13; // { dg-error "" } .*
   int T12; //should be ok
 }
@@ -116,7 +116,7 @@  template <class T12> class T12; // { dg-error "" }
 
 // 08 
 // with multiple template params, and second (third) one is redeclared
-template <class T16, int i, class T161> class Xseven { // { dg-error "" } .*
+template <class T16, int i, class T161> class Xseven { // { dg-message "" } .*
 private:
   char T161; // { dg-error "" } .*
 public:
@@ -123,7 +123,7 @@  template <class T12> class T12; // { dg-error "" }
   template <class U>
   friend bool fooy(U u);
 
-  template <class T161> // { dg-error "declaration of 'class T161'" }
+  template <class T161> // { dg-error "declaration of template parameter 'T161'" }
   friend bool foo(T161 u)
     {
       Xseven<T161, 5, int> obj;
@@ -158,7 +158,7 @@  struct S1
 // 10 
 // check for non-type parameters, should still be able to redeclare?
 // local names (14.6.1 p 4)
-template <class T18, int i> class Xten {// { dg-error "" } .*
+template <class T18, int i> class Xten {// { dg-message "" } .*
   float i; // { dg-error "" } .*
 };
 
@@ -165,7 +165,7 @@  struct S1
 
 // 11 
 // declared friend template, non-type parameters
-template <long l>// { dg-error "" } .*
+template <long l>// { dg-message "" } .*
 class Xeleven {
 public:
   template <long l> friend bool isequal (Xeleven<5> lhs, Xeleven<5> rhs);  // { dg-error "" } .*
@@ -175,7 +175,7 @@  class Xeleven {
 
 // 12
 // nested template class, non-type parameters
-template <long l>// { dg-error "" } .*
+template <long l>// { dg-message "" } .*
 class Xtwelve {
 public:
   template <long l> class nested {// { dg-error "" } .
@@ -188,7 +188,7 @@  class Xtwelve {
 
 // 13
 // member templates, non-type parameters
-template <long l>// { dg-error "" } .*
+template <long l>// { dg-message "" } .*
 struct Xthirteen {
   template <long l> long comp_ge(long test) {// { dg-error "" } .
     long local_value;
Index: testsuite/g++.old-deja/g++.benjamin/tem04.C
===================================================================
--- testsuite/g++.old-deja/g++.benjamin/tem04.C	(revision 225730)
+++ testsuite/g++.old-deja/g++.benjamin/tem04.C	(working copy)
@@ -18,7 +18,7 @@ 
 
 // 14 
 // declared friend template (v3, template type parameters)
-template <class T4>// { dg-error "" } .*
+template <class T4>// { dg-message "" } .*
 class Xfourteen {
 protected:
   T4 value;
@@ -31,7 +31,7 @@  class Xfourteen {
 
 // 15
 // nested template class (v3, template type parameters)
-template <class T6>// { dg-error "" } .*
+template <class T6>// { dg-message "" } .*
 class Xfifteen {
 protected:
   T6 value;
@@ -48,7 +48,7 @@  class Xfifteen {
 
 // 16
 // member templates (v3, template type parameters)
-template <class T8>// { dg-error "" } .*
+template <class T8>// { dg-message "" } .*
 class Xsixteen {
 protected:
   T8 value;
@@ -88,7 +88,7 @@  class Xseventeen {
 
 // 18
 // more template template redecl tests
-template <typename T14, template <typename T15> class C12>// { dg-error "" } .*
+template <typename T14, template <typename T15> class C12>// { dg-message "" } .*
 class Xeighteen {
 protected:
   C12<T14> value;
@@ -98,7 +98,7 @@  class Xeighteen {
 
 // 19
 // more template template redecl tests
-template <typename T16, template <typename T17> class C14>// { dg-error "" } .*
+template <typename T16, template <typename T17> class C14>// { dg-message "" } .*
 class Xnineteen{
 protected:
   C14<T16> value;
@@ -137,7 +137,7 @@  template <class T17, int i> struct Xtwenty {
 // non-type template parameters v1: enum
 enum my_enum {my_A = 45, my_B, my_C};
 
-template <my_enum T18> class Xtwentyone {// { dg-error "" } .*
+template <my_enum T18> class Xtwentyone {// { dg-message "" } .*
   float T18; // { dg-error "" } .*
 };
 
@@ -149,7 +149,7 @@  struct base {
   int ret_gcount() {return gcount;}
 };
 
-template <class T20, base* b> class Xtwentytwo {// { dg-error "" } .*
+template <class T20, base* b> class Xtwentytwo {// { dg-message "" } .*
   float b; // { dg-error "" } .*
 };
 
@@ -156,7 +156,7 @@  struct base {
 
 // 23
 // non-type template parameters v2: reference to object
-template <class T20, base& b2> class Xtwentythree {// { dg-error "" } .*
+template <class T20, base& b2> class Xtwentythree {// { dg-message "" } .*
   float b2; // { dg-error "" } .*
 };
 
@@ -163,7 +163,7 @@  struct base {
 
 // 24
 // non-type template parameters v3: pointer to member
-template <class T20, int base::* b3> class Xtwentyfour {// { dg-error "" } .*
+template <class T20, int base::* b3> class Xtwentyfour {// { dg-message "" } .*
   float b3; // { dg-error "" } .*
 };
 
@@ -170,13 +170,8 @@  struct base {
 
 // 25
 // non-type template parms that use push_class_level
-template <class T22> void f1() {// { dg-error "" } .*
+template <class T22> void f1() {// { dg-message "" } .*
   struct foo { 
     enum T22 { un, du, toi }; // { dg-error "" } .*
   };
 }
-
-
-
-
-
Index: testsuite/g++.old-deja/g++.brendan/crash7.C
===================================================================
--- testsuite/g++.old-deja/g++.brendan/crash7.C	(revision 225730)
+++ testsuite/g++.old-deja/g++.brendan/crash7.C	(working copy)
@@ -13,7 +13,7 @@  class Vector
   int size () { return sz; }
 };
 
-template<class T>// { dg-error "" } previous definition of T
+template<class T>// { dg-message "" } previous definition of T
 struct Comparator
 {
   typedef T T;// { dg-error "" } use of template type T in typedef to T
Index: testsuite/g++.old-deja/g++.pt/shadow2.C
===================================================================
--- testsuite/g++.old-deja/g++.pt/shadow2.C	(revision 225730)
+++ testsuite/g++.old-deja/g++.pt/shadow2.C	(working copy)
@@ -1,7 +1,7 @@ 
 // { dg-do assemble  }
 // Origin: Jason Merrill <jason@cygnus.com>
 
-template <class T> struct A { // { dg-error "" } shadowed parameter
+template <class T> struct A { // { dg-message "" } shadowed parameter
   struct B {
     void T(); // { dg-error "" } shadows template parameter
   };