public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-4728] c++: partial ordering with memfn ptr cst [PR108104]
Date: Thu, 15 Dec 2022 20:39:19 +0000 (GMT)	[thread overview]
Message-ID: <20221215203919.766E038330AF@sourceware.org> (raw)

https://gcc.gnu.org/g:38304846d18d6bb14b0fd6c627c5c6d43a814d01

commit r13-4728-g38304846d18d6bb14b0fd6c627c5c6d43a814d01
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Dec 15 15:38:47 2022 -0500

    c++: partial ordering with memfn ptr cst [PR108104]
    
    Here we're triggering an overzealous assert in unify during partial
    ordering since the member function pointer constants are represented as
    ordinary CONSTRUCTORs (with TYPE_PTRMEMFUNC_P TREE_TYPE) but the assert
    expects COMPOUND_LITERAL_P constructors.
    
            PR c++/108104
    
    gcc/cp/ChangeLog:
    
            * pt.cc (unify) <default>: Relax assert to accept any
            CONSTRUCTOR parm, not just COMPOUND_LITERAL_P one.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/template/ptrmem33.C: New test.

Diff:
---
 gcc/cp/pt.cc                             |  2 +-
 gcc/testsuite/g++.dg/template/ptrmem33.C | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 80110da2d8a..efd4eaa9afd 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -24873,7 +24873,7 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
       if (is_overloaded_fn (parm) || type_unknown_p (parm))
 	return unify_success (explain_p);
       gcc_assert (EXPR_P (parm)
-		  || COMPOUND_LITERAL_P (parm)
+		  || TREE_CODE (parm) == CONSTRUCTOR
 		  || TREE_CODE (parm) == TRAIT_EXPR);
     expr:
       /* We must be looking at an expression.  This can happen with
diff --git a/gcc/testsuite/g++.dg/template/ptrmem33.C b/gcc/testsuite/g++.dg/template/ptrmem33.C
new file mode 100644
index 00000000000..dca741ae5e2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/ptrmem33.C
@@ -0,0 +1,30 @@
+// PR c++/108104
+// { dg-do compile { target c++11 } }
+
+struct A {
+  void x();
+  void y();
+};
+
+enum State { On };
+
+template<State state, void (A::*)()>
+struct B {
+  static void f();
+};
+
+template<State state>
+struct B<state, nullptr> {
+  static void g();
+};
+
+template<State state>
+struct B<state, &A::y> {
+  static void h();
+};
+
+int main() {
+  B<State::On, &A::x>::f();
+  B<State::On, nullptr>::g();
+  B<State::On, &A::y>::h();
+}

                 reply	other threads:[~2022-12-15 20: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=20221215203919.766E038330AF@sourceware.org \
    --to=ppalka@gcc.gnu.org \
    --cc=gcc-cvs@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).