From 658b632cabdaf681ee0bd3b2ce451feab28a4396 Mon Sep 17 00:00:00 2001 From: paolo Date: Wed, 10 May 2017 08:34:02 +0000 Subject: [PATCH] /cp 2017-05-10 Paolo Carlini PR c++/80145 * decl.c (finish_function): To improve error recovery, change the logic for calling apply_deduced_return_type. /testsuite 2017-05-10 Paolo Carlini PR c++/80145 * g++.dg/cpp1y/auto-fn37.C: New. * g++.dg/cpp1y/auto-fn38.C: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@247828 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl.c | 11 +++++++---- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/cpp1y/auto-fn37.C | 5 +++++ gcc/testsuite/g++.dg/cpp1y/auto-fn38.C | 5 +++++ 5 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/auto-fn37.C create mode 100644 gcc/testsuite/g++.dg/cpp1y/auto-fn38.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7c633182666..ddc571f984f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-05-10 Paolo Carlini + + PR c++/80145 + * decl.c (finish_function): To improve error recovery, change the + logic for calling apply_deduced_return_type. + 2017-05-09 Jason Merrill * class.c (check_bases): Ignore empty bases. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 74cf018fa31..a5f62fe91dc 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -15562,16 +15562,19 @@ finish_function (int flags) if (!processing_template_decl && FNDECL_USED_AUTO (fndecl) && TREE_TYPE (fntype) == current_function_auto_return_pattern) { - if (!is_auto (current_function_auto_return_pattern) - && !current_function_returns_value && !current_function_returns_null) + if (is_auto (current_function_auto_return_pattern)) + { + apply_deduced_return_type (fndecl, void_type_node); + fntype = TREE_TYPE (fndecl); + } + else if (!current_function_returns_value + && !current_function_returns_null) { error ("no return statements in function returning %qT", current_function_auto_return_pattern); inform (input_location, "only plain % return type can be " "deduced to %"); } - apply_deduced_return_type (fndecl, void_type_node); - fntype = TREE_TYPE (fndecl); } // If this is a concept, check that the definition is reasonable. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index adec236c2ed..8ec71d72438 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2017-05-10 Paolo Carlini + + PR c++/80145 + * g++.dg/cpp1y/auto-fn37.C: New. + * g++.dg/cpp1y/auto-fn38.C: Likewise. + 2017-05-09 Michael Meissner PR target/68163 diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn37.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn37.C new file mode 100644 index 00000000000..3f664b49313 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn37.C @@ -0,0 +1,5 @@ +// PR c++/80145 +// { dg-do compile { target c++14 } } + +auto* foo() { return 0; } // { dg-error "unable to deduce" } +auto* foo(); diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn38.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn38.C new file mode 100644 index 00000000000..ec3cffb2505 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn38.C @@ -0,0 +1,5 @@ +// PR c++/80145 +// { dg-do compile { target c++14 } } + +auto* foo() { } // { dg-error "no return statements" } +auto* foo(); -- 2.11.4.GIT