diff mbox

C++ PATCH for c++/49508 (bogus return warning after error)

Message ID 54CA5A7D.7080006@redhat.com
State New
Headers show

Commit Message

Jason Merrill Jan. 29, 2015, 4:06 p.m. UTC
An erroneous return statement should not lead to a warning about a 
missing return statement.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit 2b9ed36f61ed17ee014cc8cd883eba6df2c9ef88
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Jan 29 10:16:03 2015 -0500

    	PR c++/49508
    	* semantics.c (finish_return_stmt): Suppress -Wreturn-type on
    	erroneous return statement.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 75aa501..f325e41 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -888,7 +888,13 @@  finish_return_stmt (tree expr)
 
   if (error_operand_p (expr)
       || (flag_openmp && !check_omp_return ()))
-    return error_mark_node;
+    {
+      /* Suppress -Wreturn-type for this function.  */
+      if (warn_return_type)
+	TREE_NO_WARNING (current_function_decl) = true;
+      return error_mark_node;
+    }
+
   if (!processing_template_decl)
     {
       if (warn_sequence_point)
diff --git a/gcc/testsuite/g++.old-deja/g++.jason/report.C b/gcc/testsuite/g++.old-deja/g++.jason/report.C
index b595662..e1079cf 100644
--- a/gcc/testsuite/g++.old-deja/g++.jason/report.C
+++ b/gcc/testsuite/g++.old-deja/g++.jason/report.C
@@ -72,6 +72,3 @@  int darg (char X::*p)
 {
    undef3 (1); // { dg-error "" } implicit declaration
 }				// { dg-warning "no return statement" }
-
-// { dg-message "warning: control reaches end of non-void function" "" { target *-*-* } 36 }
-// { dg-message "warning: control reaches end of non-void function" "" { target *-*-* } 65 }