aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2025-03-18 11:38:33 -0400
committerPatrick Palka <ppalka@redhat.com>2025-03-18 11:38:33 -0400
commit51b1c0a2dde8ada0856c8a8cf2c1d26ac1657787 (patch)
tree0f22cae6dc6a4705a17c03cfbdc50088c3759b52
parentd1fd9da39abc4e0430fed46d14ebd2360324f8b8 (diff)
downloadgcc-51b1c0a2dde8ada0856c8a8cf2c1d26ac1657787.zip
gcc-51b1c0a2dde8ada0856c8a8cf2c1d26ac1657787.tar.gz
gcc-51b1c0a2dde8ada0856c8a8cf2c1d26ac1657787.tar.bz2
c++: memfn pointer as NTTP argument considered unused [PR119233]
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>
-rw-r--r--gcc/cp/pt.cc6
-rw-r--r--gcc/testsuite/g++.dg/template/fn-ptr5.C28
2 files changed, 34 insertions, 0 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 8aaae44..50eda18 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -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
index 0000000..db31131
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/fn-ptr5.C
@@ -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>();
+}