[patch] PR c++/18545: backport to 3.4 branch
Volker Reichelt
reichelt@igpm.rwth-aachen.de
Thu Sep 1 14:38:00 GMT 2005
Title says it all.
Bootstrapped and regtested on i686-pc-linux-gnu.
Ok for the 3.4 branch?
Regards,
Volker
2005-09-01 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
Backport:
2004-11-25 Mark Mitchell <mark@codesourcery.com>
PR c++/18545
* typeck.c (check_return_expr): Robustify.
===================================================================
--- gcc/gcc/cp/typeck.c 2004/11/24 10:06:46 1.598
+++ gcc/gcc/cp/typeck.c 2004/11/25 17:11:37 1.599
@@ -6084,6 +6084,15 @@
/* Remember that this function did return a value. */
current_function_returns_value = 1;
+ /* Check for erroneous operands -- but after giving ourselves a
+ chance to provide an error about returning a value from a void
+ function. */
+ if (error_operand_p (retval))
+ {
+ current_function_return_value = error_mark_node;
+ return error_mark_node;
+ }
+
/* Only operator new(...) throw(), can return NULL [expr.new/13]. */
if ((DECL_OVERLOADED_OPERATOR_P (current_function_decl) == NEW_EXPR
|| DECL_OVERLOADED_OPERATOR_P (current_function_decl) == VEC_NEW_EXPR)
@@ -6140,8 +6149,8 @@
/* We don't need to do any conversions when there's nothing being
returned. */
- if (!retval || retval == error_mark_node)
- return retval;
+ if (!retval)
+ return NULL_TREE;
/* Do any required conversions. */
if (retval == result || DECL_CONSTRUCTOR_P (current_function_decl))
===================================================================
2005-09-01 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
Backport:
2004-11-25 Mark Mitchell <mark@codesourcery.com>
PR c++/18545
* g++.dg/expr/return1.C: New test.
===================================================================
--- gcc/gcc/testsuite/g++.dg/expr/return1.C
+++ gcc/gcc/testsuite/g++.dg/expr/return1.C 2005-09-01 11:57:07 +0000
@@ -0,0 +1,9 @@
+// PR c++/18545
+
+struct A;
+
+A foo()
+{ // { dg-error "incomplete" }
+ A a; // { dg-error "incomplete" }
+ return a;
+}
===================================================================
More information about the Gcc-patches
mailing list