Hi again,
this one is also matter of consistency with, say, the precise location
that we use for the error message at the beginning of check_methods.
Indeed, the sequence of error messages of g++.dg/inherit/pure1.C reflect
that. Tested x86_64-linux.
Thanks, Paolo.
PS: minor issues anyway, but I'm almost done with these low hanging
fruits which I'm proposing to fix for 9 too....
/////////////////////
/cp
2019-01-10 Paolo Carlini <paolo.carl...@oracle.com>
* decl.c (cp_finish_decl): Improve error location.
(grokfield): Likewise, improve two locations.
/testsuite
2019-01-10 Paolo Carlini <paolo.carl...@oracle.com>
* g++.dg/g++.dg/cpp0x/pr62101.C: Test locations too.
* g++.dg/inherit/pure1.C: Likewise.
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 267807)
+++ cp/decl.c (working copy)
@@ -7292,7 +7293,9 @@ cp_finish_decl (tree decl, tree init, bool init_co
synthesize_method (decl);
}
else
- error ("function %q#D is initialized like a variable", decl);
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "function %q#D is initialized like a variable",
+ decl);
}
/* else no initialization required. */
}
Index: cp/decl2.c
===================================================================
--- cp/decl2.c (revision 267807)
+++ cp/decl2.c (working copy)
@@ -925,11 +925,13 @@ grokfield (const cp_declarator *declarator,
{
gcc_assert (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE);
if (friendp)
- error ("initializer specified for friend function %qD",
- value);
+ error_at (DECL_SOURCE_LOCATION (value),
+ "initializer specified for friend function %qD",
+ value);
else
- error ("initializer specified for static member function %qD",
- value);
+ error_at (DECL_SOURCE_LOCATION (value),
+ "initializer specified for static member "
+ "function %qD", value);
}
}
else if (TREE_CODE (value) == FIELD_DECL)
Index: testsuite/g++.dg/cpp0x/pr62101.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr62101.C (revision 267807)
+++ testsuite/g++.dg/cpp0x/pr62101.C (working copy)
@@ -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;
Index: testsuite/g++.dg/inherit/pure1.C
===================================================================
--- testsuite/g++.dg/inherit/pure1.C (revision 267807)
+++ testsuite/g++.dg/inherit/pure1.C (working copy)
@@ -2,13 +2,13 @@
// Origin: Volker Reichelt <reich...@igpm.rwth-aachen.de>
// { dg-do compile }
-void foo0() = 0; // { dg-error "like a variable" }
+void foo0() = 0; // { dg-error "6:function .void foo0\\(\\).
is initialized like a variable" }
virtual void foo1() = 0; // { dg-error "1:'virtual' outside class" }
-// { dg-error "like a variable" "" { target *-*-* } .-1 }
+// { dg-error "14:function .void foo1\\(\\). is initialized like a variable"
"" { target *-*-* } .-1 }
struct A
{
- void foo2() = 0; // { dg-error "non-virtual" }
- static void foo3() = 0; // { dg-error "static member" }
+ void foo2() = 0; // { dg-error "8:initializer specified for
non-virtual method" }
+ static void foo3() = 0; // { dg-error "15:initializer specified for
static member function" }
virtual static void foo4() = 0; // { dg-error "both 'virtual' and 'static'"
}
virtual void foo5() = 0; // { dg-error "base class" }
};
@@ -15,5 +15,6 @@ struct A
struct B : A
{
- static void foo5() = 0; // { dg-error "static member|declared" }
+ static void foo5() = 0; // { dg-error "15:initializer specified for
static member function" }
+// { dg-error "declared" "" { target *-*-* } .-1 }
};