diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 691b583db3f..a13989a6607 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -12765,7 +12765,12 @@ c_finish_return (location_t loc, tree retval, tree origtype, bool musttail_p) current_function_returns_value = 1; if (t == error_mark_node) - return NULL_TREE; + { + /* Suppress -Wreturn-type for this function. */ + if (warn_return_type) + suppress_warning (current_function_decl, OPT_Wreturn_type); + return NULL_TREE; + } save = in_late_binary_op; if (C_BOOLEAN_TYPE_P (TREE_TYPE (res)) diff --git a/gcc/testsuite/gcc.dg/Wreturn-mismatch-2.c b/gcc/testsuite/gcc.dg/Wreturn-mismatch-2.c index 08811024b7e..52852261a0d 100644 --- a/gcc/testsuite/gcc.dg/Wreturn-mismatch-2.c +++ b/gcc/testsuite/gcc.dg/Wreturn-mismatch-2.c @@ -37,5 +37,5 @@ int f7 (void) { return f1 (); /* { dg-error "void value not ignored as it ought to be" } */ -} /* { dg-warning "control reaches end of non-void\[^\n\r\]*-Wreturn-type" } */ +} /* { dg-bogus "control reaches end of non-void\[^\n\r\]*-Wreturn-type" } */ diff --git a/gcc/testsuite/gcc.dg/pr60440-1.c b/gcc/testsuite/gcc.dg/pr60440-1.c new file mode 100644 index 00000000000..cd179cf1c52 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr60440-1.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-Wreturn-type" } */ + +/* PR c/60440 */ +/* Don't warn for a missing return when there was an error + on the return stamtent. */ + +int f(int a) { + return a + b; /* { dg-error "undeclared" } */ +} /* { dg-bogus "control reaches end of non-void function" } */