From patchwork Thu Jul 10 21:55:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 368817 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E50131400AF for ; Fri, 11 Jul 2014 07:55:25 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=Z8iUu7XR1MYDtjdRZEFv+qkfuz1p0ULGn6y2dDedTTnik4 VVzp8Rn5iFN9/g9qDsmnd830itOeX6wO+Wk7Wc6ViiLvCMUbAkJZhHtkbVIcU2Ei TqxhfLXAPkG0te0rF/u34FgC7eu8mXpdKRleNFA8dT456oQ5TK32R/gcZwh7U= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=R2sQznm3KEyjtA+GYHwwgWyJbmY=; b=ZY3sJEiWHws89dHmBbWx SKkQ06SCz8CYd6Z1IIbcmAplhw05NTJ955fUP3y34O+V6M9kBOxx52944avJ23o4 47Zo/l6i+6GAb1fVRvxpGPABYGS+M7nLKacL1v4FgmTX6fb+UIDXbs+5fnM/Xq1Z 1ug08+/3eM1GOCZoK0YvQZI= Received: (qmail 9299 invoked by alias); 10 Jul 2014 21:55:18 -0000 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 Received: (qmail 9273 invoked by uid 89); 10 Jul 2014 21:55:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 10 Jul 2014 21:55:15 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s6ALtEUo007799 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 10 Jul 2014 17:55:14 -0400 Received: from [10.10.116.17] ([10.10.116.17]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s6ALtDl5006739 for ; Thu, 10 Jul 2014 17:55:14 -0400 Message-ID: <53BF0BBE.6020007@redhat.com> Date: Thu, 10 Jul 2014 17:55:10 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/61661 (constexpr and ptrmem) If we handle PTRMEM_CST specially, we also need to handle any CONSTRUCTORs that wrap them. Tested x86_64-pc-linux-gnu, applying to trunk and 4.9. commit a2f90f6d52fa4c3d5391b23914c4177c3272817c Author: Jason Merrill Date: Thu Jul 10 17:05:28 2014 -0400 PR c++/61661 * semantics.c (reduced_constant_expression_p): Handle CONSTRUCTOR. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index a6f5a4a..a6d941b 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -8519,11 +8519,24 @@ cxx_eval_call_expression (const constexpr_call *old_call, tree t, bool reduced_constant_expression_p (tree t) { - if (TREE_CODE (t) == PTRMEM_CST) - /* Even if we can't lower this yet, it's constant. */ - return true; - /* FIXME are we calling this too much? */ - return initializer_constant_valid_p (t, TREE_TYPE (t)) != NULL_TREE; + switch (TREE_CODE (t)) + { + case PTRMEM_CST: + /* Even if we can't lower this yet, it's constant. */ + return true; + + case CONSTRUCTOR: + /* And we need to handle PTRMEM_CST wrapped in a CONSTRUCTOR. */ + tree elt; unsigned HOST_WIDE_INT idx; + FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (t), idx, elt) + if (!reduced_constant_expression_p (elt)) + return false; + return true; + + default: + /* FIXME are we calling this too much? */ + return initializer_constant_valid_p (t, TREE_TYPE (t)) != NULL_TREE; + } } /* Some expressions may have constant operands but are not constant diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem2.C new file mode 100644 index 0000000..86859aa --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem2.C @@ -0,0 +1,13 @@ +// PR c++/61661 +// { dg-do compile { target c++11 } } + +struct Outer { + + void Bar(); + + struct Foo { + void (Outer::*ptr)() ; + }; + + static constexpr Foo foo = { &Outer::Bar }; +};