From patchwork Fri May 6 21:47:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 94437 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 7605B1007DB for ; Sat, 7 May 2011 07:47:30 +1000 (EST) Received: (qmail 5402 invoked by alias); 6 May 2011 21:47:28 -0000 Received: (qmail 5390 invoked by uid 22791); 6 May 2011 21:47:28 -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; Fri, 06 May 2011 21:47:14 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p46LlDQB012464 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 6 May 2011 17:47:14 -0400 Received: from [127.0.0.1] (ovpn-113-126.phx2.redhat.com [10.3.113.126]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p46LlDcV009676 for ; Fri, 6 May 2011 17:47:13 -0400 Message-ID: <4DC46C60.4000304@redhat.com> Date: Fri, 06 May 2011 17:47:12 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.15) Gecko/20110421 Fedora/3.1.9-2.fc14 Lightning/1.0b2 Thunderbird/3.1.9 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/48909 (constexpr ICE) 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 Here, the problem was that in (*(first + 1) < *first) != false integral promotion changes the < expr to have type int. Then fold_binary_op_with_conditional_arg wants to change this to (*(first + 1) < *first) ? true : false without changing the type, so the condition of a ?: has the wrong type by the time we get to the constexpr expander. For 4.6, it seems simplest to fix this by making the constexpr code more permissive. Tested x86_64-pc-linux-gnu, applying to 4.6 and trunk. commit 1be580e74a6e959ffaa041b49be08c895d44eb01 Author: Jason Merrill Date: Fri May 6 10:48:52 2011 -0400 PR c++/48909 * semantics.c (cxx_eval_conditional_expression): Check integer_zerop/onep instead. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index d0c559b..cc8db90 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -6299,13 +6299,12 @@ cxx_eval_conditional_expression (const constexpr_call *call, tree t, allow_non_constant, addr, non_constant_p); VERIFY_CONSTANT (val); - if (val == boolean_true_node) - return cxx_eval_constant_expression (call, TREE_OPERAND (t, 1), + /* Don't VERIFY_CONSTANT the other operands. */ + if (integer_zerop (val)) + return cxx_eval_constant_expression (call, TREE_OPERAND (t, 2), allow_non_constant, addr, non_constant_p); - gcc_assert (val == boolean_false_node); - /* Don't VERIFY_CONSTANT here. */ - return cxx_eval_constant_expression (call, TREE_OPERAND (t, 2), + return cxx_eval_constant_expression (call, TREE_OPERAND (t, 1), allow_non_constant, addr, non_constant_p); } @@ -7872,12 +7871,12 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags) tmp = TREE_OPERAND (t, 0); if (!potential_constant_expression_1 (tmp, rval, flags)) return false; - else if (tmp == boolean_true_node) - return potential_constant_expression_1 (TREE_OPERAND (t, 1), - want_rval, flags); - else if (tmp == boolean_false_node) + else if (integer_zerop (tmp)) return potential_constant_expression_1 (TREE_OPERAND (t, 2), want_rval, flags); + else if (TREE_CODE (tmp) == INTEGER_CST) + return potential_constant_expression_1 (TREE_OPERAND (t, 1), + want_rval, flags); for (i = 1; i < 3; ++i) if (potential_constant_expression_1 (TREE_OPERAND (t, i), want_rval, tf_none)) diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-condition2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-condition2.C new file mode 100644 index 0000000..2434096 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-condition2.C @@ -0,0 +1,18 @@ +// PR c++/48909 +// { dg-options -std=c++0x } + +#define SA(X) static_assert((X),#X) + +constexpr int const * is_sorted_until(int const * first, int const * last) +{ + return first == last || first + 1 == last ? last + : (*(first + 1) < *first) != false ? first + 1 + : is_sorted_until(first + 1, last); +} + +int main() +{ + static constexpr int array[2] = {0, 1}; + constexpr int const * last = is_sorted_until(array, array + 2); + SA(last==array+2); +}