[C++] Fix confusing diagnostics for invalid overrides

Message ID 1d009675-8ffc-5d2f-42ee-532864dde8c0@netcologne.de
State New
Headers show
Series
  • [C++] Fix confusing diagnostics for invalid overrides
Related show

Commit Message

Volker Reichelt March 25, 2018, 2:18 p.m.
Hi,

when overriding a virtual function fails, the C++ front-end usually
emits two errors: one for the override that fails and one for the
function that is overridden. The second error is confusing and
should be replaced by a note to be in line with other diagnostics.

The attached patch just does that: It replaces the error/error pattern
by an error/inform pattern in search.c (check_final_overrider). And it
replaces the affected dg-error marks in the testsuite by dg-message.

Bootstrapped and regtested on x86_64-pc-linux-gnu.
OK for trunk?

Regards,
Volker


2018-03-25  Volker Reichelt <v.reichelt@netcologne.de>

     * search.c (check_final_overrider): Use inform instead of error
     for the diagnostics of the overridden functions.

===================================================================

Comments

Paolo Carlini March 25, 2018, 6:48 p.m. | #1
Hi Volker

> On 25 Mar 2018, at 16:18, Volker Reichelt <v.reichelt@netcologne.de> wrote:

> 

> Hi,

> 

> when overriding a virtual function fails, the C++ front-end usually

> emits two errors: one for the override that fails and one for the

> function that is overridden. The second error is confusing and

> should be replaced by a note to be in line with other diagnostics.

> 

> The attached patch just does that: It replaces the error/error pattern

> by an error/inform pattern in search.c (check_final_overrider). And it

> replaces the affected dg-error marks in the testsuite by dg-message.


Since you are correctly using DECL_SOURCE_LOCATION, I would recommend removing the ‘+’ modifiers, which in that case are redundant anyway and are known be a little cryptic and even causing tricky bugs together with warnings.

Cheers,
Paolo
Paolo Carlini March 25, 2018, 7:08 p.m. | #2
... oh, please also double check that with 'F' you don't need the general location_of instead of D_S_L, which normally goes with 'D' - I don't have my machines at hand to do it myself, sorry.

Paolo
Paolo Carlini March 25, 2018, 10:33 p.m. | #3
On 25/03/2018 21:08, Paolo Carlini wrote:
> ... oh, please also double check that with 'F' you don't need the general location_of instead of D_S_L, which normally goes with 'D' - I don't have my machines at hand to do it myself, sorry.

Just checked, DECL_SOURCE_LOCATION is fine.

Paolo.
Volker Reichelt March 26, 2018, 5:56 a.m. | #4
On 03/25/2018 08:48 PM, Paolo Carlini wrote:
> Hi Volker

>

>> On 25 Mar 2018, at 16:18, Volker Reichelt <v.reichelt@netcologne.de> wrote:

>>

>> Hi,

>>

>> when overriding a virtual function fails, the C++ front-end usually

>> emits two errors: one for the override that fails and one for the

>> function that is overridden. The second error is confusing and

>> should be replaced by a note to be in line with other diagnostics.

>>

>> The attached patch just does that: It replaces the error/error pattern

>> by an error/inform pattern in search.c (check_final_overrider). And it

>> replaces the affected dg-error marks in the testsuite by dg-message.

> Since you are correctly using DECL_SOURCE_LOCATION, I would recommend removing the ‘+’ modifiers, which in that case are redundant anyway and are known be a little cryptic and even causing tricky bugs together with warnings.

>

> Cheers,

> Paolo

Thanks, Paolo.
Below is an updated patch without the redundant "+" modifiers.

On 03/26/2018 12:33 AM, Paolo Carlini wrote:
> On 25/03/2018 21:08, Paolo Carlini wrote:

>> ... oh, please also double check that with 'F' you don't need the 

>> general location_of instead of D_S_L, which normally goes with 'D' - 

>> I don't have my machines at hand to do it myself, sorry.

> Just checked, DECL_SOURCE_LOCATION is fine.

>

> Paolo.


I also checked that DECL_SOURCE_LOCATION with %qF is OK.
In all the other places in the C++ frontend where %q#F or %qF is
used, DECL_SOURCE_LOCATION() is used for the corresponding argument:

   call.c (joust)
   decl.c (wrapup_namespace_globals)
   decl.c (check_redeclaration_exception_specification)
   method.c (maybe_explain_implicit_delete)

I also checked the output for that specific case manually.

Bootstrapped and regtested on x86_64-pc-linux-gnu.
OK for trunk?

Regards,
Volker


2018-03-25  Volker Reichelt  <v.reichelt@netcologne.de>

     * search.c (check_final_overrider): Use inform instead of error
     for the diagnostics of the overridden functions.

Index: gcc/cp/search.c
===================================================================
--- gcc/cp/search.c    (revision 258835)
+++ gcc/cp/search.c    (working copy)
@@ -1918,12 +1918,12 @@
        if (fail == 1)
      {
        error ("invalid covariant return type for %q+#D", overrider);
-      error ("  overriding %q+#D", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn), "  overriding %q#D", basefn);
      }
        else
      {
        error ("conflicting return type specified for %q+#D", overrider);
-      error ("  overriding %q+#D", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn), "  overriding %q#D", basefn);
      }
        DECL_INVALID_OVERRIDER_P (overrider) = 1;
        return 0;
@@ -1938,7 +1938,7 @@
    if (!comp_except_specs (base_throw, over_throw, ce_derived))
      {
        error ("looser throw specifier for %q+#F", overrider);
-      error ("  overriding %q+#F", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn), "  overriding %q#F", basefn);
        DECL_INVALID_OVERRIDER_P (overrider) = 1;
        return 0;
      }
@@ -1950,7 +1950,7 @@
        && !tx_safe_fn_type_p (over_type))
      {
        error ("conflicting type attributes specified for %q+#D", 
overrider);
-      error ("  overriding %q+#D", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn), "  overriding %q#D", basefn);
        DECL_INVALID_OVERRIDER_P (overrider) = 1;
        return 0;
      }
@@ -1975,13 +1975,15 @@
        if (DECL_DELETED_FN (overrider))
      {
        error ("deleted function %q+D", overrider);
-      error ("overriding non-deleted function %q+D", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn),
+          "overriding non-deleted function %qD", basefn);
        maybe_explain_implicit_delete (overrider);
      }
        else
      {
        error ("non-deleted function %q+D", overrider);
-      error ("overriding deleted function %q+D", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn),
+          "overriding deleted function %qD", basefn);
      }
        return 0;
      }
@@ -1988,7 +1990,8 @@
    if (DECL_FINAL_P (basefn))
      {
        error ("virtual function %q+D", overrider);
-      error ("overriding final function %q+D", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn),
+          "overriding final function %qD", basefn);
        return 0;
      }
    return 1;
===================================================================

2018-03-25  Volker Reichelt  <v.reichelt@netcologne.de>

     * g++.dg/cpp0x/defaulted2.C: Use dg-message instead of dg-error
     for the diagnostics of overridden functions.
     * g++.dg/cpp0x/implicit1.C: Likewise.
     * g++.dg/cpp0x/override1.C: Likewise.
     * g++.dg/eh/shadow1.C: Likewise.
     * g++.dg/inherit/covariant12.C: Likewise.
     * g++.dg/inherit/covariant14.C: Likewise.
     * g++.dg/inherit/covariant15.C: Likewise.
     * g++.dg/inherit/covariant16.C: Likewise.
     * g++.dg/inherit/crash3.C: Likewise.
     * g++.dg/inherit/error2.C: Likewise.
     * g++.dg/template/crash100.C: Likewise.
     * g++.old-deja/g++.eh/spec6.C: Likewise.
     * g++.old-deja/g++.mike/p811.C: Likewise.
     * g++.old-deja/g++.other/virtual11.C: Likewise.
     * g++.old-deja/g++.other/virtual4.C: Likewise.

Index: gcc/testsuite/g++.dg/cpp0x/defaulted2.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/defaulted2.C    (revision 258835)
+++ gcc/testsuite/g++.dg/cpp0x/defaulted2.C    (working copy)
@@ -25,7 +25,7 @@

  struct C
  {
-  virtual void f() = delete;    // { dg-error "overriding deleted" }
+  virtual void f() = delete;    // { dg-message "overriding deleted" }
  };

  struct D: public C
Index: gcc/testsuite/g++.dg/cpp0x/implicit1.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/implicit1.C    (revision 258835)
+++ gcc/testsuite/g++.dg/cpp0x/implicit1.C    (working copy)
@@ -7,7 +7,7 @@
  {
    void operator delete (void *); // { dg-message "private" }
  public:
-  virtual ~C();            // { dg-error "overriding" }
+  virtual ~C();            // { dg-message "overriding" }
  };

  struct D: C { };        // { dg-error "deleted" }
@@ -20,7 +20,7 @@

  struct F
  {
-  virtual ~F();            // { dg-error "overriding" }
+  virtual ~F();            // { dg-message "overriding" }
  };

  struct G: E, F { };        // { dg-error "deleted" }
Index: gcc/testsuite/g++.dg/cpp0x/override1.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/override1.C    (revision 258835)
+++ gcc/testsuite/g++.dg/cpp0x/override1.C    (working copy)
@@ -7,7 +7,7 @@
    virtual void y() final;
  };

-void B::y() {} // { dg-error "overriding" }
+void B::y() {} // { dg-message "overriding" }

  struct B2
  {
@@ -16,7 +16,7 @@

  struct D : B
  {
-  virtual void g() override final {} // { dg-error "overriding" }
+  virtual void g() override final {} // { dg-message "overriding" }
    virtual void y() override final {} // { dg-error "virtual" }
  };

Index: gcc/testsuite/g++.dg/eh/shadow1.C
===================================================================
--- gcc/testsuite/g++.dg/eh/shadow1.C    (revision 258835)
+++ gcc/testsuite/g++.dg/eh/shadow1.C    (working copy)
@@ -13,7 +13,7 @@
    friend class E;

    static B *baz (D *);
-  virtual void V () throw (B);  // { dg-error "overriding" "" { target 
{ ! c++17 } } }
+  virtual void V () throw (B);  // { dg-message "overriding" "" { 
target { ! c++17 } } }
  };                // { dg-error "dynamic exception specification" "" { 
target c++17 } .-1 }
                  // { dg-warning "deprecated" "" { target { c++11 && { 
! c++17 } } } .-2 }
  struct E : public D
Index: gcc/testsuite/g++.dg/inherit/covariant12.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/covariant12.C    (revision 258835)
+++ gcc/testsuite/g++.dg/inherit/covariant12.C    (working copy)
@@ -9,7 +9,7 @@

  struct B
  {
-  virtual T *Foo (); // { dg-error "overriding" }
+  virtual T *Foo (); // { dg-message "overriding" }
  };

  struct D : B
Index: gcc/testsuite/g++.dg/inherit/covariant14.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/covariant14.C    (revision 258835)
+++ gcc/testsuite/g++.dg/inherit/covariant14.C    (working copy)
@@ -8,7 +8,7 @@

  struct B
  {
-  virtual A* foo();  // { dg-error "overriding" }
+  virtual A* foo();  // { dg-message "overriding" }
  };

  namespace N
Index: gcc/testsuite/g++.dg/inherit/covariant15.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/covariant15.C    (revision 258835)
+++ gcc/testsuite/g++.dg/inherit/covariant15.C    (working copy)
@@ -5,7 +5,7 @@

  class B : A
  {
-    virtual A* foo(); /* { dg-error "overriding" } */
+    virtual A* foo(); /* { dg-message "overriding" } */
  };

  struct C : virtual B
Index: gcc/testsuite/g++.dg/inherit/covariant16.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/covariant16.C    (revision 258835)
+++ gcc/testsuite/g++.dg/inherit/covariant16.C    (working copy)
@@ -8,7 +8,7 @@

  struct B : virtual A
  {
-  virtual B* foo(); /* { dg-error "overriding" } */
+  virtual B* foo(); /* { dg-message "overriding" } */
  };

  struct C : B
Index: gcc/testsuite/g++.dg/inherit/crash3.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/crash3.C    (revision 258835)
+++ gcc/testsuite/g++.dg/inherit/crash3.C    (working copy)
@@ -2,7 +2,7 @@

  struct A
  {
-  virtual int& foo(); // { dg-error "overriding" }
+  virtual int& foo(); // { dg-message "overriding" }
  };

  struct B : A
Index: gcc/testsuite/g++.dg/inherit/error2.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/error2.C    (revision 258835)
+++ gcc/testsuite/g++.dg/inherit/error2.C    (working copy)
@@ -3,7 +3,7 @@

  struct A
  {
-  virtual A* foo();    // { dg-error "overriding" }
+  virtual A* foo();    // { dg-message "overriding" }
  };

  struct B : virtual A;  // { dg-error "before" }
Index: gcc/testsuite/g++.dg/template/crash100.C
===================================================================
--- gcc/testsuite/g++.dg/template/crash100.C    (revision 258835)
+++ gcc/testsuite/g++.dg/template/crash100.C    (working copy)
@@ -7,7 +7,7 @@
    public:
    operator T&(void)  { return Val; }

-  virtual T& operator=(T a ) // { dg-error "overriding" }
+  virtual T& operator=(T a ) // { dg-message "overriding" }
    {
      Val = a;
      return Val;
Index: gcc/testsuite/g++.old-deja/g++.eh/spec6.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.eh/spec6.C    (revision 258835)
+++ gcc/testsuite/g++.old-deja/g++.eh/spec6.C    (working copy)
@@ -81,19 +81,19 @@
  struct H : private E {};
  struct A
  {
-  virtual void foo() throw();             // { dg-error "" } overriding
+  virtual void foo() throw();             // { dg-message "" } overriding
    virtual void baz() throw(double, int);
    virtual void bar();
    virtual void qux() throw(E);
-  virtual void qux(int) throw(E const *); // { dg-error "" } overriding 
(pedantically)
-  virtual void quux() throw(F);           // { dg-error "" } overriding
-  virtual void quux(int) throw(F *);      // { dg-error "" } overriding
-  virtual void wibble() throw(E);         // { dg-error "" } overriding
-  virtual void wobble() throw(E *);       // { dg-error "" } overriding
-  virtual void wobble(int) throw(E *);    // { dg-error "" } overriding
+  virtual void qux(int) throw(E const *); // { dg-message "" } 
overriding (pedantically)
+  virtual void quux() throw(F);           // { dg-message "" } overriding
+  virtual void quux(int) throw(F *);      // { dg-message "" } overriding
+  virtual void wibble() throw(E);         // { dg-message "" } overriding
+  virtual void wobble() throw(E *);       // { dg-message "" } overriding
+  virtual void wobble(int) throw(E *);    // { dg-message "" } overriding
    virtual void wabble(int) throw(E *);
    virtual void wubble(int) throw(E *, H *);
-  virtual ~A() throw();                   // { dg-error "" } overriding
+  virtual ~A() throw();                   // { dg-message "" } overriding
  };

  struct B : A
@@ -115,7 +115,7 @@
  struct A1
  {
    virtual void foo() throw(int);
-  virtual void bar() throw();       // { dg-error "" } overriding
+  virtual void bar() throw();       // { dg-message "" } overriding
    virtual ~A1() throw(int);
  };

Index: gcc/testsuite/g++.old-deja/g++.mike/p811.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.mike/p811.C    (revision 258835)
+++ gcc/testsuite/g++.old-deja/g++.mike/p811.C    (working copy)
@@ -512,7 +512,7 @@
  public:
      Y() {}
    virtual const char *stringify() = 0;
-    virtual char *stringify2() const = 0; // { dg-error "overriding" }
+    virtual char *stringify2() const = 0; // { dg-message "overriding" }
  };

  class X: public Y { // { dg-message "defined here" }
Index: gcc/testsuite/g++.old-deja/g++.other/virtual11.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.other/virtual11.C    (revision 258835)
+++ gcc/testsuite/g++.old-deja/g++.other/virtual11.C    (working copy)
@@ -12,7 +12,7 @@

  struct B
  {
-  virtual void foo ();  // { dg-error "" } of this function
+  virtual void foo ();  // { dg-message "" } of this function
  };

  struct C : A , B
Index: gcc/testsuite/g++.old-deja/g++.other/virtual4.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.other/virtual4.C    (revision 258835)
+++ gcc/testsuite/g++.old-deja/g++.other/virtual4.C    (working copy)
@@ -2,7 +2,7 @@

  class A {
  public:
-  virtual int foo() = 0; // { dg-error "" } original definition
+  virtual int foo() = 0; // { dg-message "" } original definition
  };

  class B {
===================================================================
Nathan Sidwell March 26, 2018, 11:19 a.m. | #5
On 03/25/2018 10:18 AM, Volker Reichelt wrote:

> Index: gcc/cp/search.c

> ===================================================================

> --- gcc/cp/search.c    (revision 258835)

> +++ gcc/cp/search.c    (working copy)

> @@ -1918,12 +1918,14 @@

>         if (fail == 1)

>       {

>         error ("invalid covariant return type for %q+#D", overrider);

> -      error ("  overriding %q+#D", basefn);

> +      inform (DECL_SOURCE_LOCATION (basefn),

> +          "  overriding %q+#D", basefn);


In addtion to Paolo's comments, the new inform doesn't need the 
indentation.  Perhaps reword it to something like

"overridden function is %qD"

I.e. a more stand-alone message than a continuation of the error.

nathan
-- 
Nathan Sidwell
Volker Reichelt March 27, 2018, 7:08 a.m. | #6
On 03/26/2018 01:19 PM, Nathan Sidwell wrote:
> On 03/25/2018 10:18 AM, Volker Reichelt wrote:

>

>> Index: gcc/cp/search.c

>> ===================================================================

>> --- gcc/cp/search.c    (revision 258835)

>> +++ gcc/cp/search.c    (working copy)

>> @@ -1918,12 +1918,14 @@

>>         if (fail == 1)

>>       {

>>         error ("invalid covariant return type for %q+#D", overrider);

>> -      error ("  overriding %q+#D", basefn);

>> +      inform (DECL_SOURCE_LOCATION (basefn),

>> +          "  overriding %q+#D", basefn);

>

> In addtion to Paolo's comments, the new inform doesn't need the 

> indentation.  Perhaps reword it to something like

>

> "overridden function is %qD"

>

> I.e. a more stand-alone message than a continuation of the error.

>

> nathan


How about the following then?
I rephrased the last three errors a little to really make them 
stand-alone errors.

Again, bootstrapped and regtested.
OK for trunk?


2018-03-27  Volker Reichelt <v.reichelt@netcologne.de>

     * search.c (check_final_overrider): Use inform instead of error
     for the diagnostics of the overridden functions.  Tweak wording.

Index: gcc/cp/search.c
===================================================================
--- gcc/cp/search.c    (revision 258860)
+++ gcc/cp/search.c    (working copy)
@@ -1904,7 +1904,7 @@
        if (pedwarn (DECL_SOURCE_LOCATION (overrider), 0,
                 "invalid covariant return type for %q#D", overrider))
          inform (DECL_SOURCE_LOCATION (basefn),
-            "  overriding %q#D", basefn);
+            "overridden function is %q#D", basefn);
      }
        else
      fail = 2;
@@ -1918,12 +1918,14 @@
        if (fail == 1)
      {
        error ("invalid covariant return type for %q+#D", overrider);
-      error ("  overriding %q+#D", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn),
+          "overridden function is %q#D", basefn);
      }
        else
      {
        error ("conflicting return type specified for %q+#D", overrider);
-      error ("  overriding %q+#D", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn),
+          "overridden function is %q#D", basefn);
      }
        DECL_INVALID_OVERRIDER_P (overrider) = 1;
        return 0;
@@ -1938,7 +1940,8 @@
    if (!comp_except_specs (base_throw, over_throw, ce_derived))
      {
        error ("looser throw specifier for %q+#F", overrider);
-      error ("  overriding %q+#F", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn),
+          "overridden function is %q#F", basefn);
        DECL_INVALID_OVERRIDER_P (overrider) = 1;
        return 0;
      }
@@ -1950,7 +1953,8 @@
        && !tx_safe_fn_type_p (over_type))
      {
        error ("conflicting type attributes specified for %q+#D", 
overrider);
-      error ("  overriding %q+#D", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn),
+          "overridden function is %q#D", basefn);
        DECL_INVALID_OVERRIDER_P (overrider) = 1;
        return 0;
      }
@@ -1974,21 +1978,26 @@
      {
        if (DECL_DELETED_FN (overrider))
      {
-      error ("deleted function %q+D", overrider);
-      error ("overriding non-deleted function %q+D", basefn);
+      error ("deleted function %q+D overriding non-deleted function",
+         overrider);
+      inform (DECL_SOURCE_LOCATION (basefn),
+          "overridden function is %qD", basefn);
        maybe_explain_implicit_delete (overrider);
      }
        else
      {
-      error ("non-deleted function %q+D", overrider);
-      error ("overriding deleted function %q+D", basefn);
+      error ("non-deleted function %q+D overriding deleted function",
+         overrider);
+      inform (DECL_SOURCE_LOCATION (basefn),
+          "overridden function is %qD", basefn);
      }
        return 0;
      }
    if (DECL_FINAL_P (basefn))
      {
-      error ("virtual function %q+D", overrider);
-      error ("overriding final function %q+D", basefn);
+      error ("virtual function %q+D overriding final function", overrider);
+      inform (DECL_SOURCE_LOCATION (basefn),
+          "overridden function is %qD", basefn);
        return 0;
      }
    return 1;
===================================================================

2018-03-27  Volker Reichelt <v.reichelt@netcologne.de>

     * g++.dg/cpp0x/defaulted2.C: Use dg-message instead of dg-error
     for the diagnostics of overridden functions.  Adjust for new wording.
     * g++.dg/cpp0x/implicit1.C: Likewise.
     * g++.dg/cpp0x/override1.C: Likewise.
     * g++.dg/cpp1y/auto-fn18.C: Likewise.
     * g++.dg/eh/shadow1.C: Likewise.
     * g++.dg/inherit/covariant12.C: Likewise.
     * g++.dg/inherit/covariant14.C: Likewise.
     * g++.dg/inherit/covariant15.C: Likewise.
     * g++.dg/inherit/covariant16.C: Likewise.
     * g++.dg/inherit/crash3.C: Likewise.
     * g++.dg/inherit/error2.C: Likewise.
     * g++.dg/template/crash100.C: Likewise.
     * g++.old-deja/g++.eh/spec6.C: Likewise.
     * g++.old-deja/g++.mike/p811.C: Likewise.
     * g++.old-deja/g++.other/virtual11.C: Likewise.
     * g++.old-deja/g++.other/virtual4.C: Likewise.

Index: gcc/testsuite/g++.dg/cpp0x/defaulted2.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/defaulted2.C    (revision 258860)
+++ gcc/testsuite/g++.dg/cpp0x/defaulted2.C    (working copy)
@@ -25,7 +25,7 @@

  struct C
  {
-  virtual void f() = delete;    // { dg-error "overriding deleted" }
+  virtual void f() = delete;    // { dg-message "overridden" }
  };

  struct D: public C
Index: gcc/testsuite/g++.dg/cpp0x/implicit1.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/implicit1.C    (revision 258860)
+++ gcc/testsuite/g++.dg/cpp0x/implicit1.C    (working copy)
@@ -7,7 +7,7 @@
  {
    void operator delete (void *); // { dg-message "private" }
  public:
-  virtual ~C();            // { dg-error "overriding" }
+  virtual ~C();            // { dg-message "overridden" }
  };

  struct D: C { };        // { dg-error "deleted" }
@@ -20,7 +20,7 @@

  struct F
  {
-  virtual ~F();            // { dg-error "overriding" }
+  virtual ~F();            // { dg-message "overridden" }
  };

  struct G: E, F { };        // { dg-error "deleted" }
Index: gcc/testsuite/g++.dg/cpp0x/override1.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/override1.C    (revision 258860)
+++ gcc/testsuite/g++.dg/cpp0x/override1.C    (working copy)
@@ -7,7 +7,7 @@
    virtual void y() final;
  };

-void B::y() {} // { dg-error "overriding" }
+void B::y() {} // { dg-message "overridden" }

  struct B2
  {
@@ -16,7 +16,7 @@

  struct D : B
  {
-  virtual void g() override final {} // { dg-error "overriding" }
+  virtual void g() override final {} // { dg-message "overridden" }
    virtual void y() override final {} // { dg-error "virtual" }
  };

Index: gcc/testsuite/g++.dg/cpp1y/auto-fn18.C
===================================================================
--- gcc/testsuite/g++.dg/cpp1y/auto-fn18.C    (revision 258860)
+++ gcc/testsuite/g++.dg/cpp1y/auto-fn18.C    (working copy)
@@ -2,7 +2,7 @@

  struct A
  {
-  virtual int f() { return 1; }     // { dg-message "overriding" }
+  virtual int f() { return 1; }     // { dg-message "overridden" }
    virtual auto g() { return 1; } // { dg-error "virtual" }
  };

Index: gcc/testsuite/g++.dg/eh/shadow1.C
===================================================================
--- gcc/testsuite/g++.dg/eh/shadow1.C    (revision 258860)
+++ gcc/testsuite/g++.dg/eh/shadow1.C    (working copy)
@@ -13,7 +13,7 @@
    friend class E;

    static B *baz (D *);
-  virtual void V () throw (B);  // { dg-error "overriding" "" { target 
{ ! c++17 } } }
+  virtual void V () throw (B);  // { dg-message "overridden" "" { 
target { ! c++17 } } }
  };                // { dg-error "dynamic exception specification" "" { 
target c++17 } .-1 }
                  // { dg-warning "deprecated" "" { target { c++11 && { 
! c++17 } } } .-2 }
  struct E : public D
Index: gcc/testsuite/g++.dg/inherit/covariant12.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/covariant12.C    (revision 258860)
+++ gcc/testsuite/g++.dg/inherit/covariant12.C    (working copy)
@@ -9,7 +9,7 @@

  struct B
  {
-  virtual T *Foo (); // { dg-error "overriding" }
+  virtual T *Foo (); // { dg-message "overridden" }
  };

  struct D : B
Index: gcc/testsuite/g++.dg/inherit/covariant14.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/covariant14.C    (revision 258860)
+++ gcc/testsuite/g++.dg/inherit/covariant14.C    (working copy)
@@ -8,7 +8,7 @@

  struct B
  {
-  virtual A* foo();  // { dg-error "overriding" }
+  virtual A* foo();  // { dg-message "overridden" }
  };

  namespace N
Index: gcc/testsuite/g++.dg/inherit/covariant15.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/covariant15.C    (revision 258860)
+++ gcc/testsuite/g++.dg/inherit/covariant15.C    (working copy)
@@ -5,7 +5,7 @@

  class B : A
  {
-    virtual A* foo(); /* { dg-error "overriding" } */
+    virtual A* foo(); /* { dg-message "overridden" } */
  };

  struct C : virtual B
Index: gcc/testsuite/g++.dg/inherit/covariant16.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/covariant16.C    (revision 258860)
+++ gcc/testsuite/g++.dg/inherit/covariant16.C    (working copy)
@@ -8,7 +8,7 @@

  struct B : virtual A
  {
-  virtual B* foo(); /* { dg-error "overriding" } */
+  virtual B* foo(); /* { dg-message "overridden" } */
  };

  struct C : B
Index: gcc/testsuite/g++.dg/inherit/crash3.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/crash3.C    (revision 258860)
+++ gcc/testsuite/g++.dg/inherit/crash3.C    (working copy)
@@ -2,7 +2,7 @@

  struct A
  {
-  virtual int& foo(); // { dg-error "overriding" }
+  virtual int& foo(); // { dg-message "overridden" }
  };

  struct B : A
Index: gcc/testsuite/g++.dg/inherit/error2.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/error2.C    (revision 258860)
+++ gcc/testsuite/g++.dg/inherit/error2.C    (working copy)
@@ -3,7 +3,7 @@

  struct A
  {
-  virtual A* foo();    // { dg-error "overriding" }
+  virtual A* foo();    // { dg-message "overridden" }
  };

  struct B : virtual A;  // { dg-error "before" }
Index: gcc/testsuite/g++.dg/template/crash100.C
===================================================================
--- gcc/testsuite/g++.dg/template/crash100.C    (revision 258860)
+++ gcc/testsuite/g++.dg/template/crash100.C    (working copy)
@@ -7,7 +7,7 @@
    public:
    operator T&(void)  { return Val; }

-  virtual T& operator=(T a ) // { dg-error "overriding" }
+  virtual T& operator=(T a ) // { dg-message "overridden" }
    {
      Val = a;
      return Val;
Index: gcc/testsuite/g++.old-deja/g++.eh/spec6.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.eh/spec6.C    (revision 258860)
+++ gcc/testsuite/g++.old-deja/g++.eh/spec6.C    (working copy)
@@ -81,19 +81,19 @@
  struct H : private E {};
  struct A
  {
-  virtual void foo() throw();             // { dg-error "" } overriding
+  virtual void foo() throw();             // { dg-message "" } overridden
    virtual void baz() throw(double, int);
    virtual void bar();
    virtual void qux() throw(E);
-  virtual void qux(int) throw(E const *); // { dg-error "" } overriding 
(pedantically)
-  virtual void quux() throw(F);           // { dg-error "" } overriding
-  virtual void quux(int) throw(F *);      // { dg-error "" } overriding
-  virtual void wibble() throw(E);         // { dg-error "" } overriding
-  virtual void wobble() throw(E *);       // { dg-error "" } overriding
-  virtual void wobble(int) throw(E *);    // { dg-error "" } overriding
+  virtual void qux(int) throw(E const *); // { dg-message "" } 
overridden (pedantically)
+  virtual void quux() throw(F);           // { dg-message "" } overridden
+  virtual void quux(int) throw(F *);      // { dg-message "" } overridden
+  virtual void wibble() throw(E);         // { dg-message "" } overridden
+  virtual void wobble() throw(E *);       // { dg-message "" } overridden
+  virtual void wobble(int) throw(E *);    // { dg-message "" } overridden
    virtual void wabble(int) throw(E *);
    virtual void wubble(int) throw(E *, H *);
-  virtual ~A() throw();                   // { dg-error "" } overriding
+  virtual ~A() throw();                   // { dg-message "" } overriding
  };

  struct B : A
@@ -115,7 +115,7 @@
  struct A1
  {
    virtual void foo() throw(int);
-  virtual void bar() throw();       // { dg-error "" } overriding
+  virtual void bar() throw();       // { dg-message "" } overridden
    virtual ~A1() throw(int);
  };

Index: gcc/testsuite/g++.old-deja/g++.mike/p811.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.mike/p811.C    (revision 258860)
+++ gcc/testsuite/g++.old-deja/g++.mike/p811.C    (working copy)
@@ -512,7 +512,7 @@
  public:
      Y() {}
    virtual const char *stringify() = 0;
-    virtual char *stringify2() const = 0; // { dg-error "overriding" }
+    virtual char *stringify2() const = 0; // { dg-message "overridden" }
  };

  class X: public Y { // { dg-message "defined here" }
Index: gcc/testsuite/g++.old-deja/g++.other/virtual11.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.other/virtual11.C (revision 258860)
+++ gcc/testsuite/g++.old-deja/g++.other/virtual11.C (working copy)
@@ -12,7 +12,7 @@

  struct B
  {
-  virtual void foo ();  // { dg-error "" } of this function
+  virtual void foo ();  // { dg-message "" } of this function
  };

  struct C : A , B
Index: gcc/testsuite/g++.old-deja/g++.other/virtual4.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.other/virtual4.C (revision 258860)
+++ gcc/testsuite/g++.old-deja/g++.other/virtual4.C (working copy)
@@ -2,7 +2,7 @@

  class A {
  public:
-  virtual int foo() = 0; // { dg-error "" } original definition
+  virtual int foo() = 0; // { dg-message "" } original definition
  };

  class B {
===================================================================
Nathan Sidwell March 27, 2018, 10:50 a.m. | #7
On 03/27/2018 03:08 AM, Volker Reichelt wrote:
> On 03/26/2018 01:19 PM, Nathan Sidwell wrote:

>> On 03/25/2018 10:18 AM, Volker Reichelt wrote:

>>


> How about the following then?

> I rephrased the last three errors a little to really make them 

> stand-alone errors.

> 

> Again, bootstrapped and regtested.

> OK for trunk?


looks great, thanks!

nathan

-- 
Nathan Sidwell

Patch

Index: gcc/cp/search.c
===================================================================
--- gcc/cp/search.c    (revision 258835)
+++ gcc/cp/search.c    (working copy)
@@ -1918,12 +1918,14 @@ 
        if (fail == 1)
      {
        error ("invalid covariant return type for %q+#D", overrider);
-      error ("  overriding %q+#D", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn),
+          "  overriding %q+#D", basefn);
      }
        else
      {
        error ("conflicting return type specified for %q+#D", overrider);
-      error ("  overriding %q+#D", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn),
+          "  overriding %q+#D", basefn);
      }
        DECL_INVALID_OVERRIDER_P (overrider) = 1;
        return 0;
@@ -1938,7 +1940,7 @@ 
    if (!comp_except_specs (base_throw, over_throw, ce_derived))
      {
        error ("looser throw specifier for %q+#F", overrider);
-      error ("  overriding %q+#F", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn), "  overriding %q+#F", basefn);
        DECL_INVALID_OVERRIDER_P (overrider) = 1;
        return 0;
      }
@@ -1950,7 +1952,7 @@ 
        && !tx_safe_fn_type_p (over_type))
      {
        error ("conflicting type attributes specified for %q+#D", 
overrider);
-      error ("  overriding %q+#D", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn), "  overriding %q+#D", basefn);
        DECL_INVALID_OVERRIDER_P (overrider) = 1;
        return 0;
      }
@@ -1975,13 +1977,15 @@ 
        if (DECL_DELETED_FN (overrider))
      {
        error ("deleted function %q+D", overrider);
-      error ("overriding non-deleted function %q+D", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn),
+          "overriding non-deleted function %q+D", basefn);
        maybe_explain_implicit_delete (overrider);
      }
        else
      {
        error ("non-deleted function %q+D", overrider);
-      error ("overriding deleted function %q+D", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn),
+          "overriding deleted function %q+D", basefn);
      }
        return 0;
      }
@@ -1988,7 +1992,8 @@ 
    if (DECL_FINAL_P (basefn))
      {
        error ("virtual function %q+D", overrider);
-      error ("overriding final function %q+D", basefn);
+      inform (DECL_SOURCE_LOCATION (basefn),
+          "overriding final function %q+D", basefn);
        return 0;
      }
    return 1;
===================================================================

2018-03-25  Volker Reichelt <v.reichelt@netcologne.de>

     * g++.dg/cpp0x/defaulted2.C: Use dg-message instead of dg-error
     for the diagnostics of overridden functions.
     * g++.dg/cpp0x/implicit1.C: Likewise.
     * g++.dg/cpp0x/override1.C: Likewise.
     * g++.dg/eh/shadow1.C: Likewise.
     * g++.dg/inherit/covariant12.C: Likewise.
     * g++.dg/inherit/covariant14.C: Likewise.
     * g++.dg/inherit/covariant15.C: Likewise.
     * g++.dg/inherit/covariant16.C: Likewise.
     * g++.dg/inherit/crash3.C: Likewise.
     * g++.dg/inherit/error2.C: Likewise.
     * g++.dg/template/crash100.C: Likewise.
     * g++.old-deja/g++.eh/spec6.C: Likewise.
     * g++.old-deja/g++.mike/p811.C: Likewise.
     * g++.old-deja/g++.other/virtual11.C: Likewise.
     * g++.old-deja/g++.other/virtual4.C: Likewise.

Index: gcc/testsuite/g++.dg/cpp0x/defaulted2.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/defaulted2.C    (revision 258835)
+++ gcc/testsuite/g++.dg/cpp0x/defaulted2.C    (working copy)
@@ -25,7 +25,7 @@ 

  struct C
  {
-  virtual void f() = delete;    // { dg-error "overriding deleted" }
+  virtual void f() = delete;    // { dg-message "overriding deleted" }
  };

  struct D: public C
Index: gcc/testsuite/g++.dg/cpp0x/implicit1.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/implicit1.C    (revision 258835)
+++ gcc/testsuite/g++.dg/cpp0x/implicit1.C    (working copy)
@@ -7,7 +7,7 @@ 
  {
    void operator delete (void *); // { dg-message "private" }
  public:
-  virtual ~C();            // { dg-error "overriding" }
+  virtual ~C();            // { dg-message "overriding" }
  };

  struct D: C { };        // { dg-error "deleted" }
@@ -20,7 +20,7 @@ 

  struct F
  {
-  virtual ~F();            // { dg-error "overriding" }
+  virtual ~F();            // { dg-message "overriding" }
  };

  struct G: E, F { };        // { dg-error "deleted" }
Index: gcc/testsuite/g++.dg/cpp0x/override1.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/override1.C    (revision 258835)
+++ gcc/testsuite/g++.dg/cpp0x/override1.C    (working copy)
@@ -7,7 +7,7 @@ 
    virtual void y() final;
  };

-void B::y() {} // { dg-error "overriding" }
+void B::y() {} // { dg-message "overriding" }

  struct B2
  {
@@ -16,7 +16,7 @@ 

  struct D : B
  {
-  virtual void g() override final {} // { dg-error "overriding" }
+  virtual void g() override final {} // { dg-message "overriding" }
    virtual void y() override final {} // { dg-error "virtual" }
  };

Index: gcc/testsuite/g++.dg/eh/shadow1.C
===================================================================
--- gcc/testsuite/g++.dg/eh/shadow1.C    (revision 258835)
+++ gcc/testsuite/g++.dg/eh/shadow1.C    (working copy)
@@ -13,7 +13,7 @@ 
    friend class E;

    static B *baz (D *);
-  virtual void V () throw (B);  // { dg-error "overriding" "" { target 
{ ! c++17 } } }
+  virtual void V () throw (B);  // { dg-message "overriding" "" { 
target { ! c++17 } } }
  };                // { dg-error "dynamic exception specification" "" { 
target c++17 } .-1 }
                  // { dg-warning "deprecated" "" { target { c++11 && { 
! c++17 } } } .-2 }
  struct E : public D
Index: gcc/testsuite/g++.dg/inherit/covariant12.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/covariant12.C    (revision 258835)
+++ gcc/testsuite/g++.dg/inherit/covariant12.C    (working copy)
@@ -9,7 +9,7 @@ 

  struct B
  {
-  virtual T *Foo (); // { dg-error "overriding" }
+  virtual T *Foo (); // { dg-message "overriding" }
  };

  struct D : B
Index: gcc/testsuite/g++.dg/inherit/covariant14.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/covariant14.C    (revision 258835)
+++ gcc/testsuite/g++.dg/inherit/covariant14.C    (working copy)
@@ -8,7 +8,7 @@ 

  struct B
  {
-  virtual A* foo();  // { dg-error "overriding" }
+  virtual A* foo();  // { dg-message "overriding" }
  };

  namespace N
Index: gcc/testsuite/g++.dg/inherit/covariant15.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/covariant15.C    (revision 258835)
+++ gcc/testsuite/g++.dg/inherit/covariant15.C    (working copy)
@@ -5,7 +5,7 @@ 

  class B : A
  {
-    virtual A* foo(); /* { dg-error "overriding" } */
+    virtual A* foo(); /* { dg-message "overriding" } */
  };

  struct C : virtual B
Index: gcc/testsuite/g++.dg/inherit/covariant16.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/covariant16.C    (revision 258835)
+++ gcc/testsuite/g++.dg/inherit/covariant16.C    (working copy)
@@ -8,7 +8,7 @@ 

  struct B : virtual A
  {
-  virtual B* foo(); /* { dg-error "overriding" } */
+  virtual B* foo(); /* { dg-message "overriding" } */
  };

  struct C : B
Index: gcc/testsuite/g++.dg/inherit/crash3.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/crash3.C    (revision 258835)
+++ gcc/testsuite/g++.dg/inherit/crash3.C    (working copy)
@@ -2,7 +2,7 @@ 

  struct A
  {
-  virtual int& foo(); // { dg-error "overriding" }
+  virtual int& foo(); // { dg-message "overriding" }
  };

  struct B : A
Index: gcc/testsuite/g++.dg/inherit/error2.C
===================================================================
--- gcc/testsuite/g++.dg/inherit/error2.C    (revision 258835)
+++ gcc/testsuite/g++.dg/inherit/error2.C    (working copy)
@@ -3,7 +3,7 @@ 

  struct A
  {
-  virtual A* foo();    // { dg-error "overriding" }
+  virtual A* foo();    // { dg-message "overriding" }
  };

  struct B : virtual A;  // { dg-error "before" }
Index: gcc/testsuite/g++.dg/template/crash100.C
===================================================================
--- gcc/testsuite/g++.dg/template/crash100.C    (revision 258835)
+++ gcc/testsuite/g++.dg/template/crash100.C    (working copy)
@@ -7,7 +7,7 @@ 
    public:
    operator T&(void)  { return Val; }

-  virtual T& operator=(T a ) // { dg-error "overriding" }
+  virtual T& operator=(T a ) // { dg-message "overriding" }
    {
      Val = a;
      return Val;
Index: gcc/testsuite/g++.old-deja/g++.eh/spec6.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.eh/spec6.C    (revision 258835)
+++ gcc/testsuite/g++.old-deja/g++.eh/spec6.C    (working copy)
@@ -81,19 +81,19 @@ 
  struct H : private E {};
  struct A
  {
-  virtual void foo() throw();             // { dg-error "" } overriding
+  virtual void foo() throw();             // { dg-message "" } overriding
    virtual void baz() throw(double, int);
    virtual void bar();
    virtual void qux() throw(E);
-  virtual void qux(int) throw(E const *); // { dg-error "" } overriding 
(pedantically)
-  virtual void quux() throw(F);           // { dg-error "" } overriding
-  virtual void quux(int) throw(F *);      // { dg-error "" } overriding
-  virtual void wibble() throw(E);         // { dg-error "" } overriding
-  virtual void wobble() throw(E *);       // { dg-error "" } overriding
-  virtual void wobble(int) throw(E *);    // { dg-error "" } overriding
+  virtual void qux(int) throw(E const *); // { dg-message "" } 
overriding (pedantically)
+  virtual void quux() throw(F);           // { dg-message "" } overriding
+  virtual void quux(int) throw(F *);      // { dg-message "" } overriding
+  virtual void wibble() throw(E);         // { dg-message "" } overriding
+  virtual void wobble() throw(E *);       // { dg-message "" } overriding
+  virtual void wobble(int) throw(E *);    // { dg-message "" } overriding
    virtual void wabble(int) throw(E *);
    virtual void wubble(int) throw(E *, H *);
-  virtual ~A() throw();                   // { dg-error "" } overriding
+  virtual ~A() throw();                   // { dg-message "" } overriding
  };

  struct B : A
@@ -115,7 +115,7 @@ 
  struct A1
  {
    virtual void foo() throw(int);
-  virtual void bar() throw();       // { dg-error "" } overriding
+  virtual void bar() throw();       // { dg-message "" } overriding
    virtual ~A1() throw(int);
  };

Index: gcc/testsuite/g++.old-deja/g++.mike/p811.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.mike/p811.C    (revision 258835)
+++ gcc/testsuite/g++.old-deja/g++.mike/p811.C    (working copy)
@@ -512,7 +512,7 @@ 
  public:
      Y() {}
    virtual const char *stringify() = 0;
-    virtual char *stringify2() const = 0; // { dg-error "overriding" }
+    virtual char *stringify2() const = 0; // { dg-message "overriding" }
  };

  class X: public Y { // { dg-message "defined here" }
Index: gcc/testsuite/g++.old-deja/g++.other/virtual11.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.other/virtual11.C (revision 258835)
+++ gcc/testsuite/g++.old-deja/g++.other/virtual11.C (working copy)
@@ -12,7 +12,7 @@ 

  struct B
  {
-  virtual void foo ();  // { dg-error "" } of this function
+  virtual void foo ();  // { dg-message "" } of this function
  };

  struct C : A , B
Index: gcc/testsuite/g++.old-deja/g++.other/virtual4.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.other/virtual4.C (revision 258835)
+++ gcc/testsuite/g++.old-deja/g++.other/virtual4.C (working copy)
@@ -2,7 +2,7 @@ 

  class A {
  public:
-  virtual int foo() = 0; // { dg-error "" } original definition
+  virtual int foo() = 0; // { dg-message "" } original definition
  };

  class B {