From 1dee89967b74196012a4b177fed0ccce3a520706 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 4 Nov 2019 17:34:59 -0500 Subject: [PATCH] * typeck.c (check_return_expr): Avoid redundant error. From-SVN: r277798 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/typeck.c | 2 +- gcc/testsuite/g++.dg/other/return2.C | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/other/return2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 42dfc325bfa..7c22a533339 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,7 @@ +2019-11-04 Jason Merrill + + * typeck.c (check_return_expr): Avoid redundant error. + 2019-11-02 Paolo Carlini * typeck.c (composite_pointer_type): Add a const op_location_t& diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 29a2942dcaf..27d97859cb3 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -9729,7 +9729,7 @@ check_return_expr (tree retval, bool *no_warning) type. In that case, we have to evaluate the expression for its side-effects. */ finish_expr_stmt (retval); - else + else if (retval != error_mark_node) permerror (input_location, "return-statement with a value, in function " "returning %qT", valtype); diff --git a/gcc/testsuite/g++.dg/other/return2.C b/gcc/testsuite/g++.dg/other/return2.C new file mode 100644 index 00000000000..b328fa6b5f7 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/return2.C @@ -0,0 +1,7 @@ +void f(long); +void f(char); + +void g() +{ + return f(42); // { dg-error "ambiguous" } +} // { dg-bogus "void" "" { target *-*-* } .-1 } -- 2.30.2