From: Jason Merrill <jason@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [pushed] c++: constexpr PMF conversion [PR105996]
Date: Thu, 23 Mar 2023 17:39:08 -0400 [thread overview]
Message-ID: <20230323213908.2988082-1-jason@redhat.com> (raw)
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
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.cc (build_ptrmemfunc): Drop 0-offset optimization
and location wrappers.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/constexpr-pmf3.C: New test.
---
gcc/cp/typeck.cc | 13 +++++--------
gcc/testsuite/g++.dg/cpp0x/constexpr-pmf3.C | 13 +++++++++++++
2 files changed, 18 insertions(+), 8 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-pmf3.C
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index afb956087ce..8b60cbbc167 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -9960,18 +9960,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();
base-commit: 3fbeff66684d95417646aaa22d0a8f1ec9786299
--
2.31.1
reply other threads:[~2023-03-23 21:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230323213908.2988082-1-jason@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).