From patchwork Tue Jan 10 14:33:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 135247 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 421E2B6FC5 for ; Wed, 11 Jan 2012 01:34:17 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1326810857; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=qdtvUSb H+brO6FUAnEZ/CrHywDo=; b=gIkhP63Pfu8iUDOKueAVu9Vp7H+50M5INjCNNUj 1tnESCegN4r37uzTCR3qJ2JUEH9H+MAjYn0q6s+xnclN7WtBZD9lUt2vcnZqhyQ2 kGxjh3KgXDQvSDvnM59WZKN5/nc8lfMdYZbsWuYCk0rryAOvQt3mfFog7iRcwnpv 7kWY= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Sc8EuJHM3sHlYBP+TFLnWAQd3OP0S/yuVtgo5bxxEaocFOu+cODqF//tqTX+jA tMPK5qFaBqORiEa8JM30SQEbi6dYHda28nAxljvkfGI3lKnZRioWbkMWN3q6dD6J QDAafCIS5poo6fvt1Sqb2cUcWO5aovOARNaViM7RhQHGQ=; Received: (qmail 4618 invoked by alias); 10 Jan 2012 14:34:13 -0000 Received: (qmail 4519 invoked by uid 22791); 10 Jan 2012 14:34:12 -0000 X-SWARE-Spam-Status: No, hits=-6.6 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; Tue, 10 Jan 2012 14:33:59 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q0AEXx5Q001539 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 10 Jan 2012 09:33:59 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q0AEXxlO028432 for ; Tue, 10 Jan 2012 09:33:59 -0500 Received: from [0.0.0.0] (ovpn-113-101.phx2.redhat.com [10.3.113.101]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id q0AEXw8k013714 for ; Tue, 10 Jan 2012 09:33:58 -0500 Message-ID: <4F0C4C55.5050006@redhat.com> Date: Tue, 10 Jan 2012 09:33:57 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:9.0) Gecko/20111222 Thunderbird/9.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/51433 (constexpr caching) 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 Sometimes an expression that is non-constant at one point in the translation unit can become constant later, when a constexpr function is defined. So let's not cache failure. Tested x86_64-pc-linux-gnu, applying to trunk. This isn't a regression, but as before, since C++11 support is still experimental I consider patches that fix C++11 bugs and don't affect C++98 code to be acceptable. commit 639cadeb21c26f4d5e98e9bf2b211a4c39a61b9c Author: Jason Merrill Date: Mon Jan 9 09:40:34 2012 -0500 PR c++/51433 * semantics.c (cxx_eval_call_expression): Always retry previously non-constant expressions. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index fbb74e1..2c351be 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -6576,7 +6576,7 @@ cxx_eval_call_expression (const constexpr_call *old_call, tree t, else { result = entry->result; - if (!result || (result == error_mark_node && !allow_non_constant)) + if (!result || result == error_mark_node) result = (cxx_eval_constant_expression (&new_call, new_call.fundef->body, allow_non_constant, addr, diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-cache1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-cache1.C new file mode 100644 index 0000000..b6d7b64 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-cache1.C @@ -0,0 +1,9 @@ +// PR c++/51433 +// { dg-options -std=c++0x } + +constexpr int f(); +constexpr int g() { return f(); } +extern const int n = g(); // dynamic initialization +constexpr int f() { return 42; } +extern const int m = g(); +static_assert(m == 42, "m == 42");