From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 2CE343857010; Sat, 22 Apr 2023 00:23:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2CE343857010 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682122988; bh=YZxz26jzeL6SABwOxJsxmgZXizIuPWEV22Kg1WlFQ4Y=; h=From:To:Subject:Date:From; b=ZnUJy/e2DG9q7NzzmNcChZQkqOyx8ufNnMOojKNAkexzdi0l/TlBQS72ZMjCZH8i7 wCoMQ7OUAGcpG298LxcY13vpR8P/6F2SAgYpPj/9Le8fu66SJeRbbuHq1MWQm8ClLD i/oZpomQ2RVBix1Ss3rc1GUeeRDmSee2Rt3JYrzw= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-10646] c++: constexpr PMF conversion [PR105996] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 51738bb097444dd3ca7adcfa28ae8dcff5a14c50 X-Git-Newrev: b6c8048cdd2c1e523f663f248ba39caed5af90e7 Message-Id: <20230422002308.2CE343857010@sourceware.org> Date: Sat, 22 Apr 2023 00:23:07 +0000 (GMT) List-Id: https://gcc.gnu.org/g:b6c8048cdd2c1e523f663f248ba39caed5af90e7 commit r11-10646-gb6c8048cdd2c1e523f663f248ba39caed5af90e7 Author: Jason Merrill Date: Thu Mar 23 16:50:09 2023 -0400 c++: constexpr PMF conversion [PR105996] Here, we were calling build_reinterpret_cast regardless of whether there was actually a cast, and that now sets REINTERPRET_CAST_P. But that optimization seems dodgy anyway, as it involves NOP_EXPR from one RECORD_TYPE to another and we try to reserve NOP_EXPR for fundamental types. And the generated code seems the same, so let's drop it. And also strip location wrappers. PR c++/105996 gcc/cp/ChangeLog: * typeck.c (build_ptrmemfunc): Drop 0-offset optimization and location wrappers. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/constexpr-pmf3.C: New test. Diff: --- gcc/cp/typeck.c | 13 +++++-------- gcc/testsuite/g++.dg/cpp0x/constexpr-pmf3.C | 13 +++++++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index c2b703e3cf0..78d679b6c81 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -9214,18 +9214,15 @@ build_ptrmemfunc (tree type, tree pfn, int force, bool c_cast_p, if (n == error_mark_node) return error_mark_node; + STRIP_ANY_LOCATION_WRAPPER (pfn); + /* We don't have to do any conversion to convert a pointer-to-member to its own type. But, we don't want to just return a PTRMEM_CST if there's an explicit cast; that cast should make the expression an invalid template argument. */ - if (TREE_CODE (pfn) != PTRMEM_CST) - { - if (same_type_p (to_type, pfn_type)) - return pfn; - else if (integer_zerop (n) && TREE_CODE (pfn) != CONSTRUCTOR) - return build_reinterpret_cast (input_location, to_type, pfn, - complain); - } + if (TREE_CODE (pfn) != PTRMEM_CST + && same_type_p (to_type, pfn_type)) + return pfn; if (TREE_SIDE_EFFECTS (pfn)) pfn = save_expr (pfn); diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-pmf3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-pmf3.C new file mode 100644 index 00000000000..14daea312b7 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-pmf3.C @@ -0,0 +1,13 @@ +// PR c++/105996 +// { dg-do compile { target c++11 } } + +struct A { + void CB() {} +}; +struct B : public A { }; + +using APMF = void (A::*)(); +using BPMF = void (B::*)(); + +constexpr APMF foo () { return &A::CB; }; +static constexpr BPMF b = foo();