From 742b6dc476c544389f109b03d221262a4cc55aaf Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Thu, 17 Jan 2019 18:01:43 +0000 Subject: [PATCH] decl.c (grokdeclarator): Use typespec_loc in error messages about 'auto' and trailing return type. /cp 2019-01-17 Paolo Carlini * decl.c (grokdeclarator): Use typespec_loc in error messages about 'auto' and trailing return type. /testsuite 2019-01-17 Paolo Carlini * g++.dg/cpp0x/auto52.C: Test locations too. * g++.dg/cpp0x/trailing2.C: Likewise. * g++.dg/cpp1y/auto-fn18.C: Likewise. * g++.dg/cpp1y/auto-fn25.C: Likewise. * g++.dg/cpp1y/auto-fn52.C: Likewise. * g++.dg/cpp1y/auto-fn53.C: Likewise. * g++.dg/cpp1y/auto-fn54.C: Likewise. From-SVN: r268043 --- gcc/cp/ChangeLog | 5 +++ gcc/cp/decl.c | 42 ++++++++++++++------------ gcc/testsuite/ChangeLog | 10 ++++++ gcc/testsuite/g++.dg/cpp0x/auto52.C | 4 +-- gcc/testsuite/g++.dg/cpp0x/trailing2.C | 12 ++++---- gcc/testsuite/g++.dg/cpp1y/auto-fn18.C | 2 +- gcc/testsuite/g++.dg/cpp1y/auto-fn25.C | 2 +- gcc/testsuite/g++.dg/cpp1y/auto-fn52.C | 2 +- gcc/testsuite/g++.dg/cpp1y/auto-fn53.C | 2 +- gcc/testsuite/g++.dg/cpp1y/auto-fn54.C | 2 +- 10 files changed, 51 insertions(+), 32 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6893b2e4e33..05e8566e493 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-01-17 Paolo Carlini + + * decl.c (grokdeclarator): Use typespec_loc in error messages + about 'auto' and trailing return type. + 2019-01-17 David Malcolm PR c++/88699 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 9f96ebc19ef..79eeac177b6 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -11287,35 +11287,37 @@ grokdeclarator (const cp_declarator *declarator, /* OK for C++11 lambdas. */; else if (cxx_dialect < cxx14) { - error ("%qs function uses " - "% type specifier without trailing " - "return type", name); - inform (input_location, "deduced return type " - "only available with -std=c++14 or " - "-std=gnu++14"); + error_at (typespec_loc, "%qs function uses " + "% type specifier without " + "trailing return type", name); + inform (typespec_loc, + "deduced return type only available " + "with -std=c++14 or -std=gnu++14"); } else if (virtualp) { - error ("virtual function cannot " - "have deduced return type"); + error_at (typespec_loc, "virtual function " + "cannot have deduced return type"); virtualp = false; } } else if (!is_auto (type) && sfk != sfk_conversion) { - error ("%qs function with trailing return type has" - " %qT as its type rather than plain %", - name, type); + error_at (typespec_loc, "%qs function with trailing " + "return type has %qT as its type rather " + "than plain %", name, type); return error_mark_node; } else if (is_auto (type) && AUTO_IS_DECLTYPE (type)) { if (funcdecl_p) - error ("%qs function with trailing return type has " - "% as its type rather than " - "plain %", name); + error_at (typespec_loc, + "%qs function with trailing return type " + "has % as its type " + "rather than plain %", name); else - error ("invalid use of %"); + error_at (typespec_loc, + "invalid use of %"); return error_mark_node; } tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node); @@ -11359,11 +11361,13 @@ grokdeclarator (const cp_declarator *declarator, if (cxx_dialect < cxx11) /* Not using maybe_warn_cpp0x because this should always be an error. */ - error ("trailing return type only available with " - "-std=c++11 or -std=gnu++11"); + error_at (typespec_loc, + "trailing return type only available " + "with -std=c++11 or -std=gnu++11"); else - error ("%qs function with trailing return type not " - "declared with % type specifier", name); + error_at (typespec_loc, "%qs function with trailing " + "return type not declared with % " + "type specifier", name); return error_mark_node; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 176d2f8a79b..a2c71105486 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2019-01-17 Paolo Carlini + + * g++.dg/cpp0x/auto52.C: Test locations too. + * g++.dg/cpp0x/trailing2.C: Likewise. + * g++.dg/cpp1y/auto-fn18.C: Likewise. + * g++.dg/cpp1y/auto-fn25.C: Likewise. + * g++.dg/cpp1y/auto-fn52.C: Likewise. + * g++.dg/cpp1y/auto-fn53.C: Likewise. + * g++.dg/cpp1y/auto-fn54.C: Likewise. + 2019-01-17 David Malcolm PR c++/88699 diff --git a/gcc/testsuite/g++.dg/cpp0x/auto52.C b/gcc/testsuite/g++.dg/cpp0x/auto52.C index 9bfe7c754b5..d33f927a63e 100644 --- a/gcc/testsuite/g++.dg/cpp0x/auto52.C +++ b/gcc/testsuite/g++.dg/cpp0x/auto52.C @@ -2,5 +2,5 @@ // { dg-do compile { target c++11 } } using T = auto() -> int; -using U = void() -> int; // { dg-error "function with trailing return type not declared with .auto." } -using W = auto(); // { dg-error "invalid use of .auto." } +using U = void() -> int; // { dg-error "11:.type name. function with trailing return type not declared with .auto." } +using W = auto(); // { dg-error "11:invalid use of .auto." } diff --git a/gcc/testsuite/g++.dg/cpp0x/trailing2.C b/gcc/testsuite/g++.dg/cpp0x/trailing2.C index bfc2712a74a..848626a90d7 100644 --- a/gcc/testsuite/g++.dg/cpp0x/trailing2.C +++ b/gcc/testsuite/g++.dg/cpp0x/trailing2.C @@ -3,14 +3,14 @@ // { dg-do compile { target c++11 } } auto f1 () -> int; -auto f2 (); // { dg-error "without trailing return type" "" { target { ! c++14 } } } -int f3 () -> int; // { dg-error "trailing return type" } -auto *f4 () -> int; // { dg-error "trailing return type" } +auto f2 (); // { dg-error "1:.f2. function uses .auto. type specifier without trailing return type" "" { target { ! c++14 } } } +int f3 () -> int; // { dg-error "1:.f3. function with trailing return type" } +auto *f4 () -> int; // { dg-error "1:.f4. function with trailing return type" } struct A { auto f5 () const -> int; - auto f6 (); // { dg-error "without trailing return type" "" { target { ! c++14 } } } - int f7 () -> int; // { dg-error "trailing return type" } - auto *f8 () -> int; // { dg-error "trailing return type" } + auto f6 (); // { dg-error "3:.f6. function uses .auto. type specifier without trailing return type" "" { target { ! c++14 } } } + int f7 () -> int; // { dg-error "3:.f7. function with trailing return type" } + auto *f8 () -> int; // { dg-error "3:.f8. function with trailing return type" } }; diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn18.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn18.C index 1a9296459da..66cadc29942 100644 --- a/gcc/testsuite/g++.dg/cpp1y/auto-fn18.C +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn18.C @@ -3,7 +3,7 @@ struct A { virtual int f() { return 1; } // { dg-message "overridden" } - virtual auto g() { return 1; } // { dg-error "virtual" } + virtual auto g() { return 1; } // { dg-error "11:virtual" } }; struct B: A diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn25.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn25.C index fdad4653560..af986b3ff72 100644 --- a/gcc/testsuite/g++.dg/cpp1y/auto-fn25.C +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn25.C @@ -5,7 +5,7 @@ struct A { - virtual auto foo() {} // { dg-error "virtual.*deduced" } + virtual auto foo() {} // { dg-error "11:virtual.*deduced" } }; struct B : A diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn52.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn52.C index e239bc27dc2..09082dd15b9 100644 --- a/gcc/testsuite/g++.dg/cpp1y/auto-fn52.C +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn52.C @@ -1,4 +1,4 @@ // PR c++/67012 // { dg-do compile { target c++14 } } -decltype(auto) f() -> int; // { dg-error "function with trailing return type has" } +decltype(auto) f() -> int; // { dg-error "1:.f. function with trailing return type has" } diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn53.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn53.C index 720aeeb215d..1c04bb55c34 100644 --- a/gcc/testsuite/g++.dg/cpp1y/auto-fn53.C +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn53.C @@ -1,4 +1,4 @@ // PR c++/86942 // { dg-do compile { target c++14 } } -using T = decltype(auto) () -> int; // { dg-error "invalid use of" } +using T = decltype(auto) () -> int; // { dg-error "11:invalid use of" } diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn54.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn54.C index f3391ddfd75..8b5992b8f9c 100644 --- a/gcc/testsuite/g++.dg/cpp1y/auto-fn54.C +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn54.C @@ -1,3 +1,3 @@ // { dg-do compile { target c++14 } } -using T = int () -> decltype(auto); // { dg-error "function with trailing return type not declared with .auto." } +using T = int () -> decltype(auto); // { dg-error "11:.type name. function with trailing return type not declared with .auto." } -- 2.30.2