From 4b3aa535793363636b0d2819908710fae5025723 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sat, 22 Jun 2019 09:36:38 +0000 Subject: [PATCH] decl.c (grokdeclarator): Use id_loc... /cp 2019-06-22 Paolo Carlini * decl.c (grokdeclarator): Use id_loc, typespec_loc, and locations[ds_storage_class] in a few additional places. /testsuite 2019-06-22 Paolo Carlini * g++.dg/diagnostic/auto-storage-1.C: New. * g++.dg/diagnostic/no-type-1.C: Likewise. * g++.dg/diagnostic/no-type-2.C: Likewise. * g++.dg/diagnostic/top-level-auto-1.C: Likewise. * g++.dg/cpp0x/auto9.C: Test some locations too. * g++.dg/cpp1z/register1.C: Likewise. * g++.dg/cpp1z/register2.C: Likewise. * g++.dg/cpp1z/register3.C: Likewise. * g++.dg/other/error34.C: Likewise. From-SVN: r272584 --- gcc/cp/ChangeLog | 5 ++++ gcc/cp/decl.c | 24 ++++++++++++------- gcc/testsuite/ChangeLog | 12 ++++++++++ gcc/testsuite/g++.dg/cpp0x/auto9.C | 10 ++++---- gcc/testsuite/g++.dg/cpp1z/register1.C | 2 +- gcc/testsuite/g++.dg/cpp1z/register2.C | 2 +- gcc/testsuite/g++.dg/cpp1z/register3.C | 2 +- .../g++.dg/diagnostic/auto-storage-1.C | 6 +++++ gcc/testsuite/g++.dg/diagnostic/no-type-1.C | 1 + gcc/testsuite/g++.dg/diagnostic/no-type-2.C | 3 +++ .../g++.dg/diagnostic/top-level-auto-1.C | 3 +++ gcc/testsuite/g++.dg/other/error34.C | 2 +- 12 files changed, 54 insertions(+), 18 deletions(-) create mode 100644 gcc/testsuite/g++.dg/diagnostic/auto-storage-1.C create mode 100644 gcc/testsuite/g++.dg/diagnostic/no-type-1.C create mode 100644 gcc/testsuite/g++.dg/diagnostic/no-type-2.C create mode 100644 gcc/testsuite/g++.dg/diagnostic/top-level-auto-1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4d454b6f9f9..93b4875de7a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-06-22 Paolo Carlini + + * decl.c (grokdeclarator): Use id_loc, typespec_loc, and + locations[ds_storage_class] in a few additional places. + 2019-06-21 Paolo Carlini PR c++/90909 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 98b54d542a0..bcebdc9c0f5 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10816,13 +10816,14 @@ grokdeclarator (const cp_declarator *declarator, else if (in_system_header_at (input_location) || flag_ms_extensions) /* Allow it, sigh. */; else if (! is_main) - permerror (input_location, "ISO C++ forbids declaration of %qs with no type", name); + permerror (id_loc, "ISO C++ forbids declaration of %qs with no type", + name); else if (pedantic) - pedwarn (input_location, OPT_Wpedantic, + pedwarn (id_loc, OPT_Wpedantic, "ISO C++ forbids declaration of %qs with no type", name); else - warning (OPT_Wreturn_type, - "ISO C++ forbids declaration of %qs with no type", name); + warning_at (id_loc, OPT_Wreturn_type, + "ISO C++ forbids declaration of %qs with no type", name); if (type_was_error_mark_node && template_parm_flag) /* FIXME we should be able to propagate the error_mark_node as is @@ -11251,7 +11252,8 @@ grokdeclarator (const cp_declarator *declarator, else if (toplevel_bindings_p ()) { if (storage_class == sc_auto) - error ("top-level declaration of %qs specifies %", name); + error_at (declspecs->locations[ds_storage_class], + "top-level declaration of %qs specifies %", name); } else if (thread_p && storage_class != sc_extern @@ -12358,9 +12360,10 @@ grokdeclarator (const cp_declarator *declarator, && !(cxx_dialect >= cxx17 && template_parm_flag)) { if (cxx_dialect >= cxx14) - error ("% parameter not permitted in this context"); + error_at (typespec_loc, + "% parameter not permitted in this context"); else - error ("parameter declared %"); + error_at (typespec_loc, "parameter declared %"); type = error_mark_node; } @@ -12781,9 +12784,12 @@ grokdeclarator (const cp_declarator *declarator, // FIXME:gcc_assert (original_name == dname); if (storage_class == sc_auto) - error ("storage class % invalid for function %qs", name); + error_at (declspecs->locations[ds_storage_class], + "storage class % invalid for function %qs", name); else if (storage_class == sc_register) - error ("storage class % invalid for function %qs", name); + error_at (declspecs->locations[ds_storage_class], + "storage class % invalid for function %qs", + name); else if (thread_p) { if (declspecs->gnu_thread_keyword_p) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 72dcea8a4d2..80ea5916fcc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,15 @@ +2019-06-22 Paolo Carlini + + * g++.dg/diagnostic/auto-storage-1.C: New. + * g++.dg/diagnostic/no-type-1.C: Likewise. + * g++.dg/diagnostic/no-type-2.C: Likewise. + * g++.dg/diagnostic/top-level-auto-1.C: Likewise. + * g++.dg/cpp0x/auto9.C: Test some locations too. + * g++.dg/cpp1z/register1.C: Likewise. + * g++.dg/cpp1z/register2.C: Likewise. + * g++.dg/cpp1z/register3.C: Likewise. + * g++.dg/other/error34.C: Likewise. + 2019-06-21 Paolo Carlini PR c++/90909 diff --git a/gcc/testsuite/g++.dg/cpp0x/auto9.C b/gcc/testsuite/g++.dg/cpp0x/auto9.C index 8e49a01beb2..8d77b0b3667 100644 --- a/gcc/testsuite/g++.dg/cpp0x/auto9.C +++ b/gcc/testsuite/g++.dg/cpp0x/auto9.C @@ -78,10 +78,10 @@ enum struct D : auto * { FF = 0 }; // { dg-error "must be an integral type|decl void bar () { - try { } catch (auto i) { } // { dg-error "parameter" } - try { } catch (auto) { } // { dg-error "parameter" } - try { } catch (auto *i) { } // { dg-error "parameter" } - try { } catch (auto *) { } // { dg-error "parameter" } + try { } catch (auto i) { } // { dg-error "18:parameter" } + try { } catch (auto) { } // { dg-error "18:parameter" } + try { } catch (auto *i) { } // { dg-error "18:parameter" } + try { } catch (auto *) { } // { dg-error "18:parameter" } } void @@ -111,7 +111,7 @@ badthrow2 () throw (auto &) // { dg-error "invalid use of|expected" } { // { dg-error "dynamic exception specification" "" { target c++17 } .-1 } } // { dg-warning "deprecated" "" { target { ! c++17 } } .-2 } -template struct G {}; // { dg-error "auto" "" { target { ! c++17 } } } +template struct G {}; // { dg-error "11:parameter" "" { target { ! c++17 } } } template struct H { H (); ~H (); }; H h; // { dg-error "invalid|initializer" } diff --git a/gcc/testsuite/g++.dg/cpp1z/register1.C b/gcc/testsuite/g++.dg/cpp1z/register1.C index 44071bd7539..fac3498bdf2 100644 --- a/gcc/testsuite/g++.dg/cpp1z/register1.C +++ b/gcc/testsuite/g++.dg/cpp1z/register1.C @@ -10,7 +10,7 @@ register int a __asm (REG1); // { dg-bogus "ISO C\\+\\+17 does not allow 'register' storage class specifier" "" { target c++17 } } #endif register int b; // { dg-error "ISO C\\+\\+17 does not allow 'register' storage class specifier" "" { target c++17 } } -register int c (); // { dg-error "storage class 'register' invalid for function" } +register int c (); // { dg-error "1:storage class 'register' invalid for function" } int foo (register int d) // { dg-error "ISO C\\+\\+17 does not allow 'register' storage class specifier" "" { target c++17 } } { return d; diff --git a/gcc/testsuite/g++.dg/cpp1z/register2.C b/gcc/testsuite/g++.dg/cpp1z/register2.C index 5d7c9f63c30..3688f73f112 100644 --- a/gcc/testsuite/g++.dg/cpp1z/register2.C +++ b/gcc/testsuite/g++.dg/cpp1z/register2.C @@ -11,7 +11,7 @@ register int a __asm (REG1); // { dg-bogus "ISO C\\+\\+17 does not allow 'register' storage class specifier" "" { target c++17 } } #endif register int b; // { dg-bogus "ISO C\\+\\+17 does not allow 'register' storage class specifier" "" { target c++17 } } -register int c (); // { dg-error "storage class 'register' invalid for function" } +register int c (); // { dg-error "1:storage class 'register' invalid for function" } int foo (register int d) // { dg-bogus "ISO C\\+\\+17 does not allow 'register' storage class specifier" "" { target c++17 } } { return d; diff --git a/gcc/testsuite/g++.dg/cpp1z/register3.C b/gcc/testsuite/g++.dg/cpp1z/register3.C index 90b7f9d09b7..2b321166dc7 100644 --- a/gcc/testsuite/g++.dg/cpp1z/register3.C +++ b/gcc/testsuite/g++.dg/cpp1z/register3.C @@ -11,7 +11,7 @@ register int a __asm (REG1); // { dg-bogus "'register' storage class specifier used" } #endif register int b; // { dg-warning "'register' storage class specifier used" } -register int c (); // { dg-error "storage class 'register' invalid for function" } +register int c (); // { dg-error "1:storage class 'register' invalid for function" } int foo (register int d) // { dg-warning "'register' storage class specifier used" } { return d; diff --git a/gcc/testsuite/g++.dg/diagnostic/auto-storage-1.C b/gcc/testsuite/g++.dg/diagnostic/auto-storage-1.C new file mode 100644 index 00000000000..61378256bdc --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/auto-storage-1.C @@ -0,0 +1,6 @@ +// { dg-do compile { target c++98_only } } + +void foo() +{ + auto void bar(); // { dg-error "3:storage class .auto. invalid for function" } +} diff --git a/gcc/testsuite/g++.dg/diagnostic/no-type-1.C b/gcc/testsuite/g++.dg/diagnostic/no-type-1.C new file mode 100644 index 00000000000..8c892e5e350 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/no-type-1.C @@ -0,0 +1 @@ +main() {} // { dg-error "1:ISO C\\+\\+ forbids declaration" } diff --git a/gcc/testsuite/g++.dg/diagnostic/no-type-2.C b/gcc/testsuite/g++.dg/diagnostic/no-type-2.C new file mode 100644 index 00000000000..8a7c62793c2 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/no-type-2.C @@ -0,0 +1,3 @@ +// { dg-options "-w" } + +foo() {} // { dg-error "1:ISO C\\+\\+ forbids declaration" } diff --git a/gcc/testsuite/g++.dg/diagnostic/top-level-auto-1.C b/gcc/testsuite/g++.dg/diagnostic/top-level-auto-1.C new file mode 100644 index 00000000000..b9f74f76278 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/top-level-auto-1.C @@ -0,0 +1,3 @@ +// { dg-do compile { target c++98_only } } + +auto int i; // { dg-error "1:top-level declaration of .i. specifies .auto." } diff --git a/gcc/testsuite/g++.dg/other/error34.C b/gcc/testsuite/g++.dg/other/error34.C index f6b44888f48..7bcea434322 100644 --- a/gcc/testsuite/g++.dg/other/error34.C +++ b/gcc/testsuite/g++.dg/other/error34.C @@ -2,5 +2,5 @@ // { dg-do compile } // { dg-options "" } -S () : str(__PRETTY_FUNCTION__) { return S(); } // { dg-error "forbids declaration" "decl" } +S () : str(__PRETTY_FUNCTION__) { return S(); } // { dg-error "1:ISO C\\+\\+ forbids declaration" "decl" } // { dg-error "only constructors" "constructor" { target *-*-* } .-1 } -- 2.30.2