decl.c (cp_finish_decl): Improve error location.
authorPaolo Carlini <paolo.carlini@oracle.com>
Sat, 12 Jan 2019 21:59:03 +0000 (21:59 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sat, 12 Jan 2019 21:59:03 +0000 (21:59 +0000)
/cp
2019-01-12  Paolo Carlini  <paolo.carlini@oracle.com>

* decl.c (cp_finish_decl): Improve error location.
* decl2.c (grokfield): Likewise, improve two locations.

/testsuite
2019-01-12  Paolo Carlini  <paolo.carlini@oracle.com>

* g++.dg/cpp0x/pr62101.C: Test locations too.
* g++.dg/inherit/pure1.C: Likewise.

From-SVN: r267887

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/decl2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/pr62101.C

index 9c661a5ced243548191217a2d00db172069568c7..32b2ab1f82efbf369e16ba65d681bc683908bf98 100644 (file)
@@ -1,3 +1,8 @@
+2019-01-12  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * decl.c (cp_finish_decl): Improve error location.
+       * decl2.c (grokfield): Likewise, improve two locations.
+
 2019-01-11  Marek Polacek  <polacek@redhat.com>
 
        PR c++/88692, c++/87882 - -Wredundant-move false positive with *this.
index fe5403d5ab5b390faa3318489b6dd4481d95652f..6e75c3d3d93a29ff4cf0d145849571eb179e2000 100644 (file)
@@ -7293,7 +7293,10 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
                    synthesize_method (decl);
                }
              else
-               error ("function %q#D is initialized like a variable", decl);
+               error_at (cp_expr_loc_or_loc (init,
+                                             DECL_SOURCE_LOCATION (decl)),
+                         "function %q#D is initialized like a variable",
+                         decl);
            }
          /* else no initialization required.  */
        }
index 591cc21be20458dea51db798747a1a80f094f08f..e4cf4e0a361caac390dcc323a39bb06dbe20b3c8 100644 (file)
@@ -924,12 +924,14 @@ grokfield (const cp_declarator *declarator,
          else
            {
              gcc_assert (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE);
+             location_t iloc
+               = cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (value));
              if (friendp)
-               error ("initializer specified for friend function %qD",
-                      value);
+               error_at (iloc, "initializer specified for friend "
+                         "function %qD", value);
              else
-               error ("initializer specified for static member function %qD",
-                      value);
+               error_at (iloc, "initializer specified for static "
+                         "member function %qD", value);
            }
        }
       else if (TREE_CODE (value) == FIELD_DECL)
index 3d74b63c85b762bae37f55416ec5557cc4719cb5..6f781aed62ef2315df275236fb250c372645ee70 100644 (file)
@@ -1,3 +1,8 @@
+2019-01-12  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * g++.dg/cpp0x/pr62101.C: Test locations too.
+       * g++.dg/inherit/pure1.C: Likewise.
+
 2019-01-12  Paul Thomas  <pault@gcc.gnu.org>
 
        * gfortran.dg/ISO_Fortran_binding_2.f90 : Remove because of
index 2c05dd5b1a808452adb4bf2dcbe78a1e2ba078ed..5fc579c7661738094aa781437997c564824f691c 100644 (file)
@@ -3,7 +3,7 @@
 
 struct X
 {
-  friend void g(X, int) = 0; // { dg-error "initializer specified for friend function" }
+  friend void g(X, int) = 0; // { dg-error "15:initializer specified for friend function" }
   friend void g(X, int) = default; // { dg-error "cannot be defaulted" }
   // { dg-prune-output "note" }
   friend void f(X, int) = delete;