From patchwork Tue Apr 14 16:02:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 461186 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 36F8E140281 for ; Wed, 15 Apr 2015 02:02:32 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=ALmST14i; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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=MSW/5lTvRFQUXwrZ+BOQjP1vqnOuraOc0VSDlRVWN4eYqd o+17ugKHdJc16IfY5rpeHUJNxY0iFMo0o4XOStTVFWDONZN8rnuuGTLS8dTWF/Uv EUn2//Yty4k8A0KQ596+0ryNyZ1zlpmqf3ZhxmoxAy2FY8lGP027Nn/wdZJRk= 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=ShhpnL8RZlChwrw4lWYiKxACsa4=; b=ALmST14iFV0lKZnBu6w3 TvMxI8ktw87eK/DQjBBUwlujxwboe10Z2KT8NVwNtN+SW3zWqTnJRoOrXtIkVjlI 0X7flGDEPEuql9xkBcdcnw0a+aDVySz+1ynifrB82q9WoKPmL1MM0cu3ATi8gUuH pof0dvbRwQh5x2hsrTQkfxQ= Received: (qmail 85377 invoked by alias); 14 Apr 2015 16:02:22 -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 85368 invoked by uid 89); 14 Apr 2015 16:02:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD 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; Tue, 14 Apr 2015 16:02:19 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3EG2HrJ016266 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 14 Apr 2015 12:02:17 -0400 Received: from [10.10.116.43] ([10.10.116.43]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3EG2GqF015504 for ; Tue, 14 Apr 2015 12:02:17 -0400 Message-ID: <552D3A05.9010508@redhat.com> Date: Tue, 14 Apr 2015 12:02:13 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/65695 (pointer-to-member constants and constexpr) adjust_temp_type was wrapping a PTRMEM_CST in a NOP_EXPR, which confused constexpr evaluation. We can avoid this by fixing cp_fold_convert to properly fold away the conversion. Tested x86_64-pc-linux-gnu, applying to trunk. commit a5a7219fc54d6d724a032befea810910cda01fc7 Author: Jason Merrill Date: Sat Apr 11 10:57:07 2015 -0400 PR c++/65695 * cvt.c (cp_fold_convert): Avoid wrapping PTRMEM_CST in NOP_EXPR. diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index d0924f1..9aa9006 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -603,8 +603,20 @@ ignore_overflows (tree expr, tree orig) tree cp_fold_convert (tree type, tree expr) { - tree conv = fold_convert (type, expr); - conv = ignore_overflows (conv, expr); + tree conv; + if (TREE_TYPE (expr) == type) + conv = expr; + else if (TREE_CODE (expr) == PTRMEM_CST) + { + /* Avoid wrapping a PTRMEM_CST in NOP_EXPR. */ + conv = copy_node (expr); + TREE_TYPE (conv) = type; + } + else + { + conv = fold_convert (type, expr); + conv = ignore_overflows (conv, expr); + } return conv; } diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem4.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem4.C new file mode 100644 index 0000000..68788ca --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem4.C @@ -0,0 +1,26 @@ +// PR c++/65695 +// { dg-do compile { target c++11 } } + +struct Foo; + +struct Bar +{ + using MemberFuncT = int (Foo::*)(); + + MemberFuncT h_; + constexpr Bar(MemberFuncT h) : h_{h} + { + } +}; + +struct Foo +{ + int test() + { + return -1; + } + + static constexpr Bar bar {&Foo::test}; +}; + +constexpr Bar Foo::bar;