From 327d3fd01caab82dcc7720a8de7ee7487c6dbea2 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Thu, 8 Aug 2019 22:15:40 +0000 Subject: [PATCH] decl.c (grokdeclarator): Use id_loc and EXPR_LOCATION in a few error messages. /cp 2019-08-08 Paolo Carlini * decl.c (grokdeclarator): Use id_loc and EXPR_LOCATION in a few error messages. /testsuite 2019-08-08 Paolo Carlini * g++.dg/cpp0x/enum20.C: Test location(s) too. * g++.dg/other/friend3.C: Likewise. * g++.dg/parse/dtor5.C: Likewise. * g++.dg/parse/friend7.C: Likewise. * g++.dg/template/error22.C: Likewise. * g++.old-deja/g++.brendan/err-msg5.C: Likewise. From-SVN: r274220 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/decl.c | 19 +++++++++++-------- gcc/testsuite/ChangeLog | 9 +++++++++ gcc/testsuite/g++.dg/cpp0x/enum20.C | 2 +- gcc/testsuite/g++.dg/other/friend3.C | 4 ++-- gcc/testsuite/g++.dg/parse/dtor5.C | 10 +++++----- gcc/testsuite/g++.dg/parse/friend7.C | 6 ++++-- gcc/testsuite/g++.dg/template/error22.C | 2 +- gcc/testsuite/g++.old-deja/g++.brendan/err-msg5.C | 2 +- 9 files changed, 39 insertions(+), 20 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4d78888..5b0bf2b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-08-08 Paolo Carlini + + * decl.c (grokdeclarator): Use id_loc and EXPR_LOCATION in + a few error messages. + 2019-08-08 Marek Polacek PR c++/87519 - bogus warning with -Wsign-conversion. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 83f086d..b8806e4 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10579,7 +10579,8 @@ grokdeclarator (const cp_declarator *declarator, ctype = qualifying_scope; if (!MAYBE_CLASS_TYPE_P (ctype)) { - error ("%q#T is not a class or a namespace", ctype); + error_at (id_declarator->id_loc, + "%q#T is not a class or namespace", ctype); ctype = NULL_TREE; } else if (innermost_code != cdk_function @@ -10601,13 +10602,15 @@ grokdeclarator (const cp_declarator *declarator, { if (innermost_code != cdk_function) { - error ("declaration of %qD as non-function", decl); + error_at (EXPR_LOCATION (decl), + "declaration of %qE as non-function", decl); return error_mark_node; } else if (!qualifying_scope && !(current_class_type && at_class_scope_p ())) { - error ("declaration of %qD as non-member", decl); + error_at (EXPR_LOCATION (decl), + "declaration of %qE as non-member", decl); return error_mark_node; } @@ -12510,7 +12513,7 @@ grokdeclarator (const cp_declarator *declarator, else if (in_namespace && !friendp) { /* Something like struct S { int N::j; }; */ - error ("invalid use of %<::%>"); + error_at (id_loc, "invalid use of %<::%>"); return error_mark_node; } else if (FUNC_OR_METHOD_TYPE_P (type) && unqualified_id) @@ -12565,15 +12568,15 @@ grokdeclarator (const cp_declarator *declarator, if (!ctype) { gcc_assert (friendp); - error ("expected qualified name in friend declaration " - "for destructor %qD", uqname); + error_at (id_loc, "expected qualified name in friend " + "declaration for destructor %qD", uqname); return error_mark_node; } if (!check_dtor_name (ctype, TREE_OPERAND (uqname, 0))) { - error ("declaration of %qD as member of %qT", - uqname, ctype); + error_at (id_loc, "declaration of %qD as member of %qT", + uqname, ctype); return error_mark_node; } if (concept_p) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 94b8852..6d49b6d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2019-08-08 Paolo Carlini + + * g++.dg/cpp0x/enum20.C: Test location(s) too. + * g++.dg/other/friend3.C: Likewise. + * g++.dg/parse/dtor5.C: Likewise. + * g++.dg/parse/friend7.C: Likewise. + * g++.dg/template/error22.C: Likewise. + * g++.old-deja/g++.brendan/err-msg5.C: Likewise. + 2019-08-08 Jim Wilson PR target/91229 diff --git a/gcc/testsuite/g++.dg/cpp0x/enum20.C b/gcc/testsuite/g++.dg/cpp0x/enum20.C index 8937cc7..f39933a 100644 --- a/gcc/testsuite/g++.dg/cpp0x/enum20.C +++ b/gcc/testsuite/g++.dg/cpp0x/enum20.C @@ -2,4 +2,4 @@ // { dg-do compile { target c++11 } } enum A { }; -void A::f() { } // { dg-error "not a class" } +void A::f() { } // { dg-error "6:.enum A. is not a class" } diff --git a/gcc/testsuite/g++.dg/other/friend3.C b/gcc/testsuite/g++.dg/other/friend3.C index ce872e5..cf74606 100644 --- a/gcc/testsuite/g++.dg/other/friend3.C +++ b/gcc/testsuite/g++.dg/other/friend3.C @@ -4,10 +4,10 @@ struct A { - friend ~A(); // { dg-error "qualified name" } + friend ~A(); // { dg-error "10:expected qualified name" } }; struct B { - friend ~A(); // { dg-error "qualified name" } + friend ~A(); // { dg-error "10:expected qualified name" } }; diff --git a/gcc/testsuite/g++.dg/parse/dtor5.C b/gcc/testsuite/g++.dg/parse/dtor5.C index 297a0e7..3cb569a 100644 --- a/gcc/testsuite/g++.dg/parse/dtor5.C +++ b/gcc/testsuite/g++.dg/parse/dtor5.C @@ -1,12 +1,12 @@ // PR c++/19732 struct A; -typedef int ~A; // { dg-error "non-function" } +typedef int ~A; // { dg-error "13:declaration of .~ A. as non-function" } struct B { - ~A(); // { dg-error "" } - typedef int ~A; // { dg-error "non-function" } + ~A(); // { dg-error "3:declaration of .~A. as member of .B." } + typedef int ~A; // { dg-error "15:declaration of .~ A. as non-function" } void f() { - extern ~B(); // { dg-error "non-member" } + extern ~B(); // { dg-error "12:declaration of .~ B. as non-member" } } }; -void ~A(); // { dg-error "non-member" } +void ~A(); // { dg-error "6:declaration of .~ A. as non-member" } diff --git a/gcc/testsuite/g++.dg/parse/friend7.C b/gcc/testsuite/g++.dg/parse/friend7.C index 7fc480f..19e3179 100644 --- a/gcc/testsuite/g++.dg/parse/friend7.C +++ b/gcc/testsuite/g++.dg/parse/friend7.C @@ -19,14 +19,16 @@ struct B struct C { friend int C (); - friend int ~C (); // { dg-error "return type|in friend decl" } + friend int ~C (); // { dg-error "10:return type" } + // { dg-error "14:expected qualified name in friend decl" "" { target *-*-* } .-1 } friend int C (const C &); }; struct D { friend int D () {} - friend int ~D () {} // { dg-error "return type|in friend decl" } + friend int ~D () {} // { dg-error "10:return type" } + // { dg-error "14:expected qualified name in friend decl" "" { target *-*-* } .-1 } friend int D (const D &) {} }; diff --git a/gcc/testsuite/g++.dg/template/error22.C b/gcc/testsuite/g++.dg/template/error22.C index d793fe4..a7e6172 100644 --- a/gcc/testsuite/g++.dg/template/error22.C +++ b/gcc/testsuite/g++.dg/template/error22.C @@ -3,7 +3,7 @@ struct A { template struct B {}; - void ::foo(); // { dg-error "invalid use" } + void ::foo(); // { dg-error "10:invalid use" } B<&A::foo> b; // { dg-error "incomplete type|template argument" } }; diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/err-msg5.C b/gcc/testsuite/g++.old-deja/g++.brendan/err-msg5.C index 1837e2f..460d65c 100644 --- a/gcc/testsuite/g++.old-deja/g++.brendan/err-msg5.C +++ b/gcc/testsuite/g++.old-deja/g++.brendan/err-msg5.C @@ -1,4 +1,4 @@ // { dg-do assemble } // GROUPS passed error-messages class foo {}; -~foo () {}// { dg-error "" } destructors must be member functions.* +~foo () {}// { dg-error "1:declaration of .~ foo. as non-member" } destructors must be member functions.* -- 2.7.4