This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 22434
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 2 Nov 2005 17:34:13 -0800
- Subject: C++ PATCH: PR 22434
- Reply-to: mark at codesourcery dot com
This patch fixes PR c++/22434, an ICE on invalid code. We were
getting confused in the front-end on conditional expressions. In
particular, you're supposed to try converting the second argument to
the type of the third, and vice versa. When we're not being pedantic,
we can get "bad" conversions -- i.e., conversions that we know how to
do, but don't like. We should generally ignore those -- but if that's
our only choice, we should use them -- which may generate warnings or
errors. In this case, we forgot to use them.
Tested on x86_64-unknown-linux-gnu, applied on the mainline and on the
4.0 branch.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2005-11-02 Mark Mitchell <mark@codesourcery.com>
PR c++/22434
* call.c (build_conditional_expr): Do bad conversions, if there's
no other choice.
2005-11-02 Mark Mitchell <mark@codesourcery.com>
PR c++/22434
* g++.dg/expr/cond8.C: New test.
Index: gcc/cp/call.c
===================================================================
--- gcc/cp/call.c (revision 106407)
+++ gcc/cp/call.c (working copy)
@@ -3281,13 +3281,13 @@ build_conditional_expr (tree arg1, tree
error ("operands to ?: have different types");
result = error_mark_node;
}
- else if (conv2 && !conv2->bad_p)
+ else if (conv2 && (!conv2->bad_p || !conv3))
{
arg2 = convert_like (conv2, arg2);
arg2 = convert_from_reference (arg2);
arg2_type = TREE_TYPE (arg2);
}
- else if (conv3 && !conv3->bad_p)
+ else if (conv3 && (!conv3->bad_p || !conv2))
{
arg3 = convert_like (conv3, arg3);
arg3 = convert_from_reference (arg3);
Index: gcc/testsuite/g++.dg/expr/cond8.C
===================================================================
--- gcc/testsuite/g++.dg/expr/cond8.C (revision 0)
+++ gcc/testsuite/g++.dg/expr/cond8.C (revision 0)
@@ -0,0 +1,12 @@
+// PR c++/22434
+
+struct A
+{
+ A(void*);
+ ~A();
+};
+
+void foo(const int i, bool b)
+{
+ b ? A(0) : i; // { dg-error "conversion" }
+}