From 062ab4596d7b684f3781db1d484e5a9f1c9f5fd9 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sat, 12 Jan 2019 21:59:03 +0000 Subject: [PATCH] decl.c (cp_finish_decl): Improve error location. /cp 2019-01-12 Paolo Carlini * decl.c (cp_finish_decl): Improve error location. * decl2.c (grokfield): Likewise, improve two locations. /testsuite 2019-01-12 Paolo Carlini * g++.dg/cpp0x/pr62101.C: Test locations too. * g++.dg/inherit/pure1.C: Likewise. From-SVN: r267887 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/decl.c | 5 ++++- gcc/cp/decl2.c | 10 ++++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/pr62101.C | 2 +- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9c661a5ced2..32b2ab1f82e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-01-12 Paolo Carlini + + * decl.c (cp_finish_decl): Improve error location. + * decl2.c (grokfield): Likewise, improve two locations. + 2019-01-11 Marek Polacek PR c++/88692, c++/87882 - -Wredundant-move false positive with *this. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index fe5403d5ab5..6e75c3d3d93 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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. */ } diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 591cc21be20..e4cf4e0a361 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -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) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3d74b63c85b..6f781aed62e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-01-12 Paolo Carlini + + * g++.dg/cpp0x/pr62101.C: Test locations too. + * g++.dg/inherit/pure1.C: Likewise. + 2019-01-12 Paul Thomas * gfortran.dg/ISO_Fortran_binding_2.f90 : Remove because of diff --git a/gcc/testsuite/g++.dg/cpp0x/pr62101.C b/gcc/testsuite/g++.dg/cpp0x/pr62101.C index 2c05dd5b1a8..5fc579c7661 100644 --- a/gcc/testsuite/g++.dg/cpp0x/pr62101.C +++ b/gcc/testsuite/g++.dg/cpp0x/pr62101.C @@ -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; -- 2.30.2