From 13ff3e166de379e0386bfaeadf3ae5fba56a0ef5 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 24 Aug 2018 15:48:43 +0000 Subject: [PATCH] re PR c++/67012 (decltype(auto) with trailing return type) PR c++/67012 PR c++/86942 * decl.c (grokdeclarator): Disallow functions with trailing return type with decltype(auto) as its type. Also check the function if it's inner declarator doesn't exist * g++.dg/cpp0x/auto52.C: New test. * g++.dg/cpp1y/auto-fn52.C: New test. * g++.dg/cpp1y/auto-fn53.C: New test. * g++.dg/cpp1y/auto-fn54.C: New test. From-SVN: r263836 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/decl.c | 15 ++++++++++++++- gcc/testsuite/ChangeLog | 9 +++++++++ gcc/testsuite/g++.dg/cpp0x/auto52.C | 6 ++++++ gcc/testsuite/g++.dg/cpp1y/auto-fn52.C | 4 ++++ gcc/testsuite/g++.dg/cpp1y/auto-fn53.C | 4 ++++ gcc/testsuite/g++.dg/cpp1y/auto-fn54.C | 3 +++ 7 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/auto52.C create mode 100644 gcc/testsuite/g++.dg/cpp1y/auto-fn52.C create mode 100644 gcc/testsuite/g++.dg/cpp1y/auto-fn53.C create mode 100644 gcc/testsuite/g++.dg/cpp1y/auto-fn54.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0fbd816..ccb771b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2018-08-24 Marek Polacek + + PR c++/67012 + PR c++/86942 + * decl.c (grokdeclarator): Disallow functions with trailing return + type with decltype(auto) as its type. Also check the function if + it's inner declarator doesn't exist + 2018-08-21 Marek Polacek PR c++/86499 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 82ec4af..9056ad0 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -11246,7 +11246,10 @@ grokdeclarator (const cp_declarator *declarator, /* Handle a late-specified return type. */ tree late_return_type = declarator->u.function.late_return_type; - if (funcdecl_p) + if (funcdecl_p + /* This is the case e.g. for + using T = auto () -> int. */ + || inner_declarator == NULL) { if (tree auto_node = type_uses_auto (type)) { @@ -11278,6 +11281,16 @@ grokdeclarator (const cp_declarator *declarator, 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); + else + error ("invalid use of %"); + return error_mark_node; + } tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node); if (!tmpl) if (tree late_auto = type_uses_auto (late_return_type)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c6b6198..eafd7ecd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2018-08-24 Marek Polacek + + PR c++/67012 + PR c++/86942 + * g++.dg/cpp0x/auto52.C: New test. + * g++.dg/cpp1y/auto-fn52.C: New test. + * g++.dg/cpp1y/auto-fn53.C: New test. + * g++.dg/cpp1y/auto-fn54.C: New test. + 2018-08-24 Richard Sandiford * lib/target-supports.exp (vect_perm_supported): Only return diff --git a/gcc/testsuite/g++.dg/cpp0x/auto52.C b/gcc/testsuite/g++.dg/cpp0x/auto52.C new file mode 100644 index 0000000..9bfe7c7 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/auto52.C @@ -0,0 +1,6 @@ +// PR c++/86942 +// { 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." } diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn52.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn52.C new file mode 100644 index 0000000..e239bc2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn52.C @@ -0,0 +1,4 @@ +// PR c++/67012 +// { dg-do compile { target c++14 } } + +decltype(auto) f() -> int; // { dg-error "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 new file mode 100644 index 0000000..720aeeb --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn53.C @@ -0,0 +1,4 @@ +// PR c++/86942 +// { dg-do compile { target c++14 } } + +using T = decltype(auto) () -> int; // { dg-error "invalid use of" } diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn54.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn54.C new file mode 100644 index 0000000..f3391dd --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn54.C @@ -0,0 +1,3 @@ +// { dg-do compile { target c++14 } } + +using T = int () -> decltype(auto); // { dg-error "function with trailing return type not declared with .auto." } -- 2.7.4