From d6c057abd6a83513d4b6356314b8c5752a7025af Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 12 Nov 2009 15:26:36 -0500 Subject: [PATCH] re PR c++/42013 (cv-qualification of conditional expression type depending on the value of its first expression?!?) PR c++/42013 * call.c (build_conditional_expr): Check specifically for folding to CALL_EXPR rather than TREE_SIDE_EFFECTS. From-SVN: r154129 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/call.c | 11 ++++++----- gcc/testsuite/g++.dg/cpp0x/decltype19.C | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 861835b383d..e0b5f2771da 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2009-11-12 Jason Merrill + + PR c++/42013 + * call.c (build_conditional_expr): Check specifically for folding + to CALL_EXPR rather than TREE_SIDE_EFFECTS. + 2009-11-12 Jason Merrill * typeck.c (cv_qualified_p): New fn. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index e77a738660d..e4a6bca347f 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -3605,6 +3605,7 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3, tree arg2_type; tree arg3_type; tree result = NULL_TREE; + tree result_save; tree result_type = NULL_TREE; bool lvalue_p = true; struct z_candidate *candidates = 0; @@ -3991,12 +3992,12 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3, } valid_operands: - result = build3 (COND_EXPR, result_type, arg1, arg2, arg3); + result_save = build3 (COND_EXPR, result_type, arg1, arg2, arg3); + result = fold_if_not_in_template (result_save); - if (cp_unevaluated_operand && TREE_SIDE_EFFECTS (result)) - /* Avoid folding a ?: of two calls within decltype (c++/42013). */; - else - result = fold_if_not_in_template (result); + if (cp_unevaluated_operand && TREE_CODE (result) == CALL_EXPR) + /* Avoid folding to a CALL_EXPR within decltype (c++/42013). */ + result = result_save; /* We can't use result_type below, as fold might have returned a throw_expr. */ diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype19.C b/gcc/testsuite/g++.dg/cpp0x/decltype19.C index 33ca71ff492..41d602f34eb 100644 --- a/gcc/testsuite/g++.dg/cpp0x/decltype19.C +++ b/gcc/testsuite/g++.dg/cpp0x/decltype19.C @@ -2,7 +2,7 @@ template _Tp -declval(); +__attribute ((const)) declval(); template struct common_type