C++ PATCH: PR 27666
Mark Mitchell
mark@codesourcery.com
Fri Jun 16 06:09:00 GMT 2006
This patch fixes an ICE-on-invalid regression with conditional
conversions. We forgot that even though the conversion may be valid
(from the point of view of things like overload resolution), it may be
invalid in actual fact.
Tested on x86_64-unknown-linux-gnu, applied on the mainline. I will
apply to 4.1 as soon as testing completes.
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
2006-06-15 Mark Mitchell <mark@codesourcery.com>
PR c++/27666
* call.c (build_conditional_expr): Robustify.
2006-06-15 Mark Mitchell <mark@codesourcery.com>
PR c++/27666
* g++.dg/expr/cond9.C: New test.
Index: gcc/cp/call.c
===================================================================
--- gcc/cp/call.c (revision 114635)
+++ gcc/cp/call.c (working copy)
@@ -3322,12 +3322,21 @@ build_conditional_expr (tree arg1, tree
arg2 = convert_like (conv2, arg2);
arg2 = convert_from_reference (arg2);
arg2_type = TREE_TYPE (arg2);
+ /* Even if CONV2 is a valid conversion, the result of the
+ conversion may be invalid. For example, if ARG3 has type
+ "volatile X", and X does not have a copy constructor
+ accepting a "volatile X&", then even if ARG2 can be
+ converted to X, the conversion will fail. */
+ if (error_operand_p (arg2))
+ result = error_mark_node;
}
else if (conv3 && (!conv3->bad_p || !conv2))
{
arg3 = convert_like (conv3, arg3);
arg3 = convert_from_reference (arg3);
arg3_type = TREE_TYPE (arg3);
+ if (error_operand_p (arg3))
+ result = error_mark_node;
}
/* Free all the conversions we allocated. */
Index: gcc/testsuite/g++.dg/expr/cond9.C
===================================================================
--- gcc/testsuite/g++.dg/expr/cond9.C (revision 0)
+++ gcc/testsuite/g++.dg/expr/cond9.C (revision 0)
@@ -0,0 +1,10 @@
+// PR c++/27666
+
+struct A { // { dg-error "A" }
+ A(int); // { dg-error "A" }
+};
+
+void foo(volatile A a) {
+ 1 ? a : 0; // { dg-error "match|temporary" }
+ 1 ? 0 : a; // { dg-error "match|temporary" }
+}
More information about the Gcc-patches
mailing list