From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19289 invoked by alias); 27 May 2011 16:45:15 -0000 Received: (qmail 19276 invoked by uid 22791); 27 May 2011 16:45:14 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 27 May 2011 16:44:59 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4RGixPg030735 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 27 May 2011 12:44:59 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p4RGiwYb021241 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 27 May 2011 12:44:58 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p4RGivA2006918; Fri, 27 May 2011 18:44:57 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p4RGivS4006916; Fri, 27 May 2011 18:44:57 +0200 Date: Fri, 27 May 2011 18:14:00 -0000 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix another y && (x ? 1 : throw 1) issue (PR c++/49165) Message-ID: <20110527164457.GD17079@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-05/txt/msg02187.txt.bz2 Hi! As the testcase shows (it is eh/cond5.C just with s/true :/1 :/g), c_common_truthvalue_conversion needs to be aware of void type arms too, otherwise it errors on valid source. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.6? 2011-05-27 Jakub Jelinek PR c++/49165 * c-common.c (c_common_truthvalue_conversion) : For C++ don't call c_common_truthvalue_conversion on void type arms. * g++.dg/eh/cond6.C: New test. --- gcc/c-family/c-common.c.jj 2011-05-25 16:50:57.000000000 +0200 +++ gcc/c-family/c-common.c 2011-05-27 14:22:06.000000000 +0200 @@ -3942,14 +3942,15 @@ c_common_truthvalue_conversion (location /* Distribute the conversion into the arms of a COND_EXPR. */ if (c_dialect_cxx ()) { + tree op1 = TREE_OPERAND (expr, 1); + tree op2 = TREE_OPERAND (expr, 2); + /* In C++ one of the arms might have void type if it is throw. */ + if (!VOID_TYPE_P (TREE_TYPE (op1))) + op1 = c_common_truthvalue_conversion (location, op1); + if (!VOID_TYPE_P (TREE_TYPE (op2))) + op2 = c_common_truthvalue_conversion (location, op2); expr = fold_build3_loc (location, COND_EXPR, truthvalue_type_node, - TREE_OPERAND (expr, 0), - c_common_truthvalue_conversion (location, - TREE_OPERAND (expr, - 1)), - c_common_truthvalue_conversion (location, - TREE_OPERAND (expr, - 2))); + TREE_OPERAND (expr, 0), op1, op2); goto ret; } else --- gcc/testsuite/g++.dg/eh/cond6.C.jj 2011-05-27 14:25:02.000000000 +0200 +++ gcc/testsuite/g++.dg/eh/cond6.C 2011-05-27 14:13:17.000000000 +0200 @@ -0,0 +1,43 @@ +// PR c++/49165 +// { dg-do run } + +extern "C" void abort (); + +int +foo (bool x, int y) +{ + if (y < 10 && (x ? 1 : throw 1)) + y++; + if (y > 20 || (x ? 1 : throw 2)) + y++; + return y; +} + +int +main () +{ + if (foo (true, 0) != 2 + || foo (true, 10) != 11 + || foo (false, 30) != 31) + abort (); + try + { + foo (false, 0); + abort (); + } + catch (int i) + { + if (i != 1) + abort (); + } + try + { + foo (false, 10); + abort (); + } + catch (int i) + { + if (i != 2) + abort (); + } +} Jakub