]> 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>
Wed, 19 Mar 2025 18:23:49 +0000 (14:23 -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>
(cherry picked from commit 51b1c0a2dde8ada0856c8a8cf2c1d26ac1657787)

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

index a1dd428cd10e6fc0dc964211fd864d46c27deb3d..ca34ed75d659907c69242076d34cbd73ae9e9480 100644 (file)
@@ -22060,6 +22060,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>();
+}