]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: memfn pointer as NTTP argument considered unused [PR119233]
authorPatrick Palka <ppalka@redhat.com>
Tue, 18 Mar 2025 15:38:33 +0000 (11:38 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 18 Mar 2025 15:38:33 +0000 (11:38 -0400)
This is just the member function pointer version of PR c++/105848,
in which our non-dependent call pruning may cause us to not mark an
otherwise unused function pointer template argument as used.

PR c++/119233

gcc/cp/ChangeLog:

* pt.cc (mark_template_arguments_used): Also handle member
function pointers.

gcc/testsuite/ChangeLog:

* g++.dg/template/fn-ptr5.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/pt.cc
gcc/testsuite/g++.dg/template/fn-ptr5.C [new file with mode: 0644]

index 8aaae44686871cfdc1d2a6ca556e4833e1df39c6..50eda189c43a1d02a8a12b5d8347410ad05aecb2 100644 (file)
@@ -22491,6 +22491,12 @@ mark_template_arguments_used (tree tmpl, tree args)
              gcc_checking_assert (ok || seen_error ());
            }
        }
+      /* A member function pointer.  */
+      else if (TREE_CODE (arg) == PTRMEM_CST)
+       {
+         bool ok = mark_used (PTRMEM_CST_MEMBER (arg), tf_none);
+         gcc_checking_assert (ok || seen_error ());
+       }
       /* A class NTTP argument.  */
       else if (VAR_P (arg)
               && DECL_NTTP_OBJECT_P (arg))
diff --git a/gcc/testsuite/g++.dg/template/fn-ptr5.C b/gcc/testsuite/g++.dg/template/fn-ptr5.C
new file mode 100644 (file)
index 0000000..db31131
--- /dev/null
@@ -0,0 +1,28 @@
+// PR c++/119233
+// A version of fn-ptr3a.C using member instead of non-member function
+// pointers.
+
+struct B {
+  template<class T>
+  void f(T) { T::fail; } // { dg-error "fail" }
+};
+
+template<void (B::*P)(int)>
+struct A {
+  // P not called
+};
+
+template<void (B::*P)(char)>
+void wrap() {
+  // P not called
+}
+
+template<int>
+void g() {
+  A<&B::f> a; // { dg-message "required from" }
+  wrap<&B::f>(); // { dg-message "required from" }
+}
+
+int main() {
+  g<0>();
+}