From 57ea629b50c80a54fa5122c7d2368c2a5660a665 Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 26 Aug 2009 04:35:17 +0000 Subject: [PATCH] * call.c (build_conditional_expr): Fix logic errors. (build_new_op): Remove dead COND_EXPR handling. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@151113 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/call.c | 38 +++++++++-------------------------- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/overload/cond2.C | 15 ++++++++++++++ 4 files changed, 33 insertions(+), 29 deletions(-) create mode 100644 gcc/testsuite/g++.dg/overload/cond2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6c9d217..e7f4500 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2009-08-26 Jason Merrill + + * call.c (build_conditional_expr): Fix logic errors. + (build_new_op): Remove dead COND_EXPR handling. + 2009-08-24 Jason Merrill * cp-tree.h (DECL_DEFERRED_FN): Remove. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index f6a083b..8dc6d2a 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -3791,7 +3791,7 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3, bool any_viable_p; /* Rearrange the arguments so that add_builtin_candidate only has - to know about two args. In build_builtin_candidates, the + to know about two args. In build_builtin_candidate, the arguments are unscrambled. */ args[0] = arg2; args[1] = arg3; @@ -3837,8 +3837,10 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3, arg1 = convert_like (conv, arg1, complain); conv = cand->convs[1]; arg2 = convert_like (conv, arg2, complain); + arg2_type = TREE_TYPE (arg2); conv = cand->convs[2]; arg3 = convert_like (conv, arg3, complain); + arg3_type = TREE_TYPE (arg3); } /* [expr.cond] @@ -3857,7 +3859,7 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3, arg2_type = TREE_TYPE (arg2); arg3 = force_rvalue (arg3); - if (!CLASS_TYPE_P (arg2_type)) + if (!CLASS_TYPE_P (arg3_type)) arg3_type = TREE_TYPE (arg3); if (arg2 == error_mark_node || arg3 == error_mark_node) @@ -4157,14 +4159,8 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, arg3 = prep_operand (arg3); if (code == COND_EXPR) - { - if (arg2 == NULL_TREE - || TREE_CODE (TREE_TYPE (arg2)) == VOID_TYPE - || TREE_CODE (TREE_TYPE (arg3)) == VOID_TYPE - || (! IS_OVERLOAD_TYPE (TREE_TYPE (arg2)) - && ! IS_OVERLOAD_TYPE (TREE_TYPE (arg3)))) - goto builtin; - } + /* Use build_conditional_expr instead. */ + gcc_unreachable (); else if (! IS_OVERLOAD_TYPE (TREE_TYPE (arg1)) && (! arg2 || ! IS_OVERLOAD_TYPE (TREE_TYPE (arg2)))) goto builtin; @@ -4206,22 +4202,9 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, flags, &candidates); } - /* Rearrange the arguments for ?: so that add_builtin_candidate only has - to know about two args; a builtin candidate will always have a first - parameter of type bool. We'll handle that in - build_builtin_candidate. */ - if (code == COND_EXPR) - { - args[0] = arg2; - args[1] = arg3; - args[2] = arg1; - } - else - { - args[0] = arg1; - args[1] = arg2; - args[2] = NULL_TREE; - } + args[0] = arg1; + args[1] = arg2; + args[2] = NULL_TREE; add_builtin_candidates (&candidates, code, code2, fnname, args, flags); @@ -4463,9 +4446,6 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, case ARRAY_REF: return build_array_ref (input_location, arg1, arg2); - case COND_EXPR: - return build_conditional_expr (arg1, arg2, arg3, complain); - case MEMBER_REF: return build_m_component_ref (cp_build_indirect_ref (arg1, NULL, complain), diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 54c86c8..d465ac2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2009-08-26 Jason Merrill + + * g++.dg/overload/cond2.C: New. + 2009-08-25 Kaz Kojima * gcc.dg/torture/builtin-math-7.c: Add -mieee for sh*-*-* targets. diff --git a/gcc/testsuite/g++.dg/overload/cond2.C b/gcc/testsuite/g++.dg/overload/cond2.C new file mode 100644 index 0000000..cbcdc6e --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/cond2.C @@ -0,0 +1,15 @@ +struct C +{ + operator int(); +}; + +struct D +{ + operator int(); +}; + +int main() +{ + C c; D d; + true ? c : d; +} -- 2.7.4