From: Paolo Carlini Date: Wed, 16 Jan 2019 16:16:54 +0000 (+0000) Subject: decl.c (grokdeclarator): Use locations[ds_storage_class] in error messages about... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=59ec4914775d554368879fd1d67b416daf9406d4;p=gcc.git decl.c (grokdeclarator): Use locations[ds_storage_class] in error messages about ill-formed uses of mutable. /cp 2019-01-16 Paolo Carlini * decl.c (grokdeclarator): Use locations[ds_storage_class] in error messages about ill-formed uses of mutable. /testsuite 2019-01-16 Paolo Carlini * g++.dg/other/pr33558.C: Test location too. * g++.dg/other/pr33558-2.C: Likewise. * g++.dg/parse/crash4.C: Likewise. * g++.old-deja/g++.brendan/err-msg11.C: Likewise. * g++.old-deja/g++.mike/p7635.C: Likewise. * g++.old-deja/g++.other/decl6.C: Likewise. From-SVN: r267978 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6adb0e44d7e..50f00f2e4c4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-01-16 Paolo Carlini + + * decl.c (grokdeclarator): Use locations[ds_storage_class] in + error messages about ill-formed uses of mutable. + 2019-01-16 Marek Polacek PR c++/78244 - narrowing conversion in template not detected. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 8e1d12d8feb..9f96ebc19ef 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -11902,36 +11902,43 @@ grokdeclarator (const cp_declarator *declarator, if (storage_class == sc_mutable) { + location_t sloc = declspecs->locations[ds_storage_class]; if (decl_context != FIELD || friendp) { - error ("non-member %qs cannot be declared %", name); + error_at (sloc, "non-member %qs cannot be declared %", + name); storage_class = sc_none; } else if (decl_context == TYPENAME || typedef_p) { - error ("non-object member %qs cannot be declared %", name); + error_at (sloc, + "non-object member %qs cannot be declared %", + name); storage_class = sc_none; } else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) { - error ("function %qs cannot be declared %", name); + error_at (sloc, "function %qs cannot be declared %", + name); storage_class = sc_none; } else if (staticp) { - error ("static %qs cannot be declared %", name); + error_at (sloc, "% %qs cannot be declared %", + name); storage_class = sc_none; } else if (type_quals & TYPE_QUAL_CONST) { - error ("const %qs cannot be declared %", name); + error_at (sloc, "% %qs cannot be declared %", + name); storage_class = sc_none; } else if (TYPE_REF_P (type)) { - permerror (input_location, "reference %qs cannot be declared " - "%", name); + permerror (sloc, "reference %qs cannot be declared %", + name); storage_class = sc_none; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index df36f5e8315..6c11b84797e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2019-01-16 Paolo Carlini + + * g++.dg/other/pr33558.C: Test location too. + * g++.dg/other/pr33558-2.C: Likewise. + * g++.dg/parse/crash4.C: Likewise. + * g++.old-deja/g++.brendan/err-msg11.C: Likewise. + * g++.old-deja/g++.mike/p7635.C: Likewise. + * g++.old-deja/g++.other/decl6.C: Likewise. + 2019-01-16 Marek Polacek PR c++/78244 - narrowing conversion in template not detected. diff --git a/gcc/testsuite/g++.dg/other/pr33558-2.C b/gcc/testsuite/g++.dg/other/pr33558-2.C index a8df840b7a8..4b539774074 100644 --- a/gcc/testsuite/g++.dg/other/pr33558-2.C +++ b/gcc/testsuite/g++.dg/other/pr33558-2.C @@ -2,5 +2,5 @@ /* { dg-options "-fpermissive" } */ class X { - mutable int &q; /* { dg-warning "cannot be declared 'mutable'" } */ + mutable int &q; /* { dg-warning "3:reference .q. cannot be declared .mutable." } */ }; diff --git a/gcc/testsuite/g++.dg/other/pr33558.C b/gcc/testsuite/g++.dg/other/pr33558.C index 1a340af5972..2372a5cb0fd 100644 --- a/gcc/testsuite/g++.dg/other/pr33558.C +++ b/gcc/testsuite/g++.dg/other/pr33558.C @@ -1,5 +1,5 @@ /* { dg-do compile } */ class X { - mutable int &q; /* { dg-error "cannot be declared 'mutable'" } */ + mutable int &q; /* { dg-error "3:reference .q. cannot be declared .mutable." } */ }; diff --git a/gcc/testsuite/g++.dg/parse/crash4.C b/gcc/testsuite/g++.dg/parse/crash4.C index a24f0dd003c..e5e95800c80 100644 --- a/gcc/testsuite/g++.dg/parse/crash4.C +++ b/gcc/testsuite/g++.dg/parse/crash4.C @@ -7,6 +7,6 @@ struct Bar { void func(void) { - mutable Bar::type x; // { dg-error "" } + mutable Bar::type x; // { dg-error "8:non-member .x. cannot be declared .mutable." } } }; diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/err-msg11.C b/gcc/testsuite/g++.old-deja/g++.brendan/err-msg11.C index abfe0e12753..3a405e8ea24 100644 --- a/gcc/testsuite/g++.old-deja/g++.brendan/err-msg11.C +++ b/gcc/testsuite/g++.old-deja/g++.brendan/err-msg11.C @@ -1,3 +1,3 @@ // { dg-do assemble } // GROUPS passed error-messages -void foo (mutable int x);// { dg-error "" } non-member `x' cannot be declared `mutable'.* +void foo (mutable int x);// { dg-error "11:non-member .x. cannot be declared .mutable." } non-member `x' cannot be declared `mutable'.* diff --git a/gcc/testsuite/g++.old-deja/g++.mike/p7635.C b/gcc/testsuite/g++.old-deja/g++.mike/p7635.C index ac31af202a5..db7c56661c1 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/p7635.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/p7635.C @@ -3,5 +3,5 @@ class DaycountBasis { mutable const int * p; - mutable int * const q; // { dg-error "" } + mutable int * const q; // { dg-error "3:.const. .q. cannot be declared .mutable." } }; diff --git a/gcc/testsuite/g++.old-deja/g++.other/decl6.C b/gcc/testsuite/g++.old-deja/g++.other/decl6.C index 40247b81eb4..60edc54c564 100644 --- a/gcc/testsuite/g++.old-deja/g++.other/decl6.C +++ b/gcc/testsuite/g++.old-deja/g++.other/decl6.C @@ -11,16 +11,16 @@ struct A friend explicit B::B (); // { dg-error "" } only ctor decls can be explicit int f(const); // { dg-error "" } ansi forbids no type const k; // { dg-error "" } ansi forbids no type - mutable friend int j1 (); // { dg-error "" } non-member cannot be mutable + mutable friend int j1 (); // { dg-error "3:storage class specifiers" } non-member cannot be mutable mutable typedef int d; // { dg-error "" } non-object cannot be mutable - mutable int fn (); // { dg-error "" } non-object cannot be mutable - void fn (mutable int); // { dg-error "" } non-member cannot be mutable + mutable int fn (); // { dg-error "3:function .fn. cannot be declared .mutable." } non-object cannot be mutable + void fn (mutable int); // { dg-error "12:non-member .parameter. cannot be declared .mutable." } non-member cannot be mutable mutable static int s; // { dg-error "" } static cannot be mutable - mutable const int s1; // { dg-error "" } const cannot be mutable + mutable const int s1; // { dg-error "3:.const. .s1. cannot be declared .mutable." } const cannot be mutable mutable const int *s2; // ok - mutable int *const s3; // { dg-error "" } const cannot be mutable + mutable int *const s3; // { dg-error "3:.const. .s3. cannot be declared .mutable." } const cannot be mutable explicit A (); // ok }; -mutable int g; // { dg-error "" } non-member cannot be mutable +mutable int g; // { dg-error "1:non-member .g. cannot be declared .mutable." } non-member cannot be mutable explicit A::A () {} // { dg-error "" } only ctor decls can be explicit