]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: partial ordering with memfn ptr cst [PR108104]
authorPatrick Palka <ppalka@redhat.com>
Thu, 15 Dec 2022 20:38:47 +0000 (15:38 -0500)
committerPatrick Palka <ppalka@redhat.com>
Mon, 19 Dec 2022 16:54:14 +0000 (11:54 -0500)
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.

(cherry picked from commit 38304846d18d6bb14b0fd6c627c5c6d43a814d01)

gcc/cp/pt.cc
gcc/testsuite/g++.dg/template/ptrmem33.C [new file with mode: 0644]

index a5f14ef98e8643254bc74914e320c4fbca21223e..d4c32ce60259ecc026bf38a31955ae091a35b404 100644 (file)
@@ -24810,7 +24810,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 (file)
index 0000000..dca741a
--- /dev/null
@@ -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();
+}