From: Gabriel Dos Reis Date: Sun, 16 May 2004 22:52:19 +0000 (+0000) Subject: backport: call.c (build_conditional_expr): Do not call force_rvalue for operands... X-Git-Tag: releases/gcc-3.3.4~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=956cde8f206024b3188041c508717a1d06cac2f5;p=thirdparty%2Fgcc.git backport: call.c (build_conditional_expr): Do not call force_rvalue for operands of void_type when... Backport from mainline: 2004-03-18 Mark Mitchell * call.c (build_conditional_expr): Do not call force_rvalue for operands of void_type when the conditional expression itself has void type. From-SVN: r81927 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 85adf271e050..b508b2fe5228 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2004-05-16 Gabriel Dos Reis + + Backport from mainline: + 2004-03-18 Mark Mitchell + * call.c (build_conditional_expr): Do not call force_rvalue for + operands of void_type when the conditional expression itself has + void type. + 2004-05-08 Kaveh R. Ghazi * Make-lang.in (cp/init.o): Depend on diagnostic.h. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index e45d5aaee0cc..313460b69845 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -3242,18 +3242,24 @@ build_conditional_expr (arg1, arg2, arg3) type of the other and is an rvalue. --Both the second and the third operands have type void; the - result is of type void and is an rvalue. */ + result is of type void and is an rvalue. + + We must avoid calling force_rvalue for expressions of type + "void" because it will complain that their value is being + used. */ if (TREE_CODE (arg2) == THROW_EXPR && TREE_CODE (arg3) != THROW_EXPR) { - arg3 = force_rvalue (arg3); + if (!VOID_TYPE_P (arg3_type)) + 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); + if (!VOID_TYPE_P (arg2_type)) + arg2 = force_rvalue (arg2); arg2_type = TREE_TYPE (arg2); result_type = arg2_type; } diff --git a/gcc/testsuite/g++.dg/expr/cond5.C b/gcc/testsuite/g++.dg/expr/cond5.C new file mode 100644 index 000000000000..cb62dd1cfa47 --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/cond5.C @@ -0,0 +1,3 @@ +void f() { + true ? throw 1 : (void)7; +}