From 41dffe622d75043716fa6aaea7bba387751d7441 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Fri, 13 Feb 2004 20:11:35 +0000 Subject: [PATCH] re PR c++/14083 (ICE in conditional expression operator with throw) PR c++/14083 * call.c (build_conditional_expr): Call force_rvalue on the non-void operand in the case that one result is a throw-expression and the other is not. PR c++/14083 * g++.dg/eh/cond2.C: New test. From-SVN: r77768 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/call.c | 18 ++++++++++++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/eh/cond2.C | 19 +++++++++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/eh/cond2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4238dea0fc55..89d8edc8d818 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2004-02-13 Mark Mitchell + + PR c++/14083 + * call.c (build_conditional_expr): Call force_rvalue on the + non-void operand in the case that one result is a throw-expression + and the other is not. + 2004-02-13 Ian Lance Taylor PR c++/9851 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 0f7c9e56dc08..ba3b2287f85c 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -3179,10 +3179,20 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3) --Both the second and the third operands have type void; the result is of type void and is an rvalue. */ - if ((TREE_CODE (arg2) == THROW_EXPR) - ^ (TREE_CODE (arg3) == THROW_EXPR)) - result_type = ((TREE_CODE (arg2) == THROW_EXPR) - ? arg3_type : arg2_type); + if (TREE_CODE (arg2) == THROW_EXPR + && TREE_CODE (arg3) != THROW_EXPR) + { + arg3 = force_rvalue (arg3); + arg3_type = TREE_TYPE (arg3); + result_type = arg3_type; + } + else if (TREE_CODE (arg2) != THROW_EXPR + && TREE_CODE (arg3) == THROW_EXPR) + { + arg2 = force_rvalue (arg2); + arg2_type = TREE_TYPE (arg2); + result_type = arg2_type; + } else if (VOID_TYPE_P (arg2_type) && VOID_TYPE_P (arg3_type)) result_type = void_type_node; else diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cc197d4efe9a..dd136645c6d5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-02-13 Mark Mitchell + + PR c++/14083 + * g++.dg/eh/cond2.C: New test. + 2004-02-12 Alan Modra * gcc.dg/debug/20020327-1.c: Disable for powerpc64. diff --git a/gcc/testsuite/g++.dg/eh/cond2.C b/gcc/testsuite/g++.dg/eh/cond2.C new file mode 100644 index 000000000000..e4b45f7a46f8 --- /dev/null +++ b/gcc/testsuite/g++.dg/eh/cond2.C @@ -0,0 +1,19 @@ +// PR c++/14083 + +struct A { + A() throw() { } + A(const A&) throw() { } +}; + +struct X { + A a; + X(); + X& operator=(const X& __str); +}; + +bool operator==(const X& __lhs, const char* __rhs); + +int main() { + X x; + x=="" ? x : throw 1; +} -- 2.47.2