From patchwork Thu Mar 17 02:25:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 87328 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id A0ACAB6FC1 for ; Thu, 17 Mar 2011 13:26:17 +1100 (EST) Received: (qmail 28097 invoked by alias); 17 Mar 2011 02:26:16 -0000 Received: (qmail 28089 invoked by uid 22791); 17 Mar 2011 02:26:15 -0000 X-SWARE-Spam-Status: No, hits=-6.3 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; Thu, 17 Mar 2011 02:26:07 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2H2Q6tn005299 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 16 Mar 2011 22:26:06 -0400 Received: from [127.0.0.1] (ovpn-113-145.phx2.redhat.com [10.3.113.145]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p2H2Q5Pw001412 for ; Wed, 16 Mar 2011 22:26:05 -0400 Message-ID: <4D817137.8000403@redhat.com> Date: Wed, 16 Mar 2011 22:25:59 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.15) Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Lightning/1.0b2 Thunderbird/3.1.9 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/47570 (constexpr failure with >=) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org In this case, fold is turning one() >= 0 into (one(), true) because the comparison is always true because one() returns unsigned, and we were handling COMPOUND_EXPR like any other binary expression, expecting fold to turn (1, 1) into 1. But it doesn't, and it makes sense to handle COMPOUND_EXPR differently. Tested x86_64-pc-linux-gnu, applying to trunk. commit ff191a21f0a3dbff8ab4d2788e3fa5b072657c6e Author: Jason Merrill Date: Wed Mar 16 16:50:10 2011 -0400 PR c++/47570 * semantics.c (cxx_eval_constant_expression) [COMPOUND_EXPR]: Don't use the generic binary expression handling. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index ce24d46..a0c5ae3 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -6915,7 +6915,13 @@ cxx_eval_constant_expression (const constexpr_call *call, tree t, r = cxx_eval_constant_expression (call, op0, allow_non_constant, addr, non_constant_p); else - goto binary; + { + /* Check that the LHS is constant and then discard it. */ + cxx_eval_constant_expression (call, op0, allow_non_constant, + false, non_constant_p); + r = cxx_eval_constant_expression (call, op1, allow_non_constant, + addr, non_constant_p); + } } break; @@ -6957,7 +6963,6 @@ cxx_eval_constant_expression (const constexpr_call *call, tree t, case UNEQ_EXPR: case RANGE_EXPR: case COMPLEX_EXPR: - binary: r = cxx_eval_binary_expression (call, t, allow_non_constant, addr, non_constant_p); break; diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-47570.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-47570.C new file mode 100644 index 0000000..c60ba86 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-47570.C @@ -0,0 +1,25 @@ +// PR c++/47570 +// { dg-options -std=c++0x } + +unsigned int constexpr one() +{ return 1; } + +int constexpr one_B() +{ return 1; } + +int main() +{ + // FAIL TO COMPILE: + static bool constexpr SC_huh1 = ((unsigned int)one()) >= ((unsigned int)0); + static bool constexpr SC_huh2 = one() >= ((unsigned int)0); + static bool constexpr SC_huh3 = one() >= 0; + + // COMPILE OK: + static bool constexpr SC_huh4 = ((one() == 0) || (one() > 0)); + static bool constexpr SC_huh5 = one() == 0; + static bool constexpr SC_huh6 = one() > 0; + static bool constexpr SC_huh7 = one_B() >= 0; + static bool constexpr SC_huh8 = one() >= 1; + + return SC_huh3; +}