]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/reflection: fix type_of for member fns [PR123934]
authorMarek Polacek <polacek@redhat.com>
Wed, 4 Feb 2026 16:31:02 +0000 (11:31 -0500)
committerMarek Polacek <polacek@redhat.com>
Thu, 5 Feb 2026 14:16:57 +0000 (09:16 -0500)
Here the assert was wrongly failing with

  'void (struct F::)(int)' is not the same as 'void(int)'

but as per [dcl.fct]/1 the type of fType should not include the class F.

PR c++/123934

gcc/cp/ChangeLog:

* reflect.cc (type_of): For FUNCTION_DECLs, use static_fn_type.

gcc/testsuite/ChangeLog:

* g++.dg/reflect/type_of2.C: Uncomment an assert.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/reflect.cc
gcc/testsuite/g++.dg/reflect/type_of2.C

index 624414e234665fdda99ed9a3187da9cd14ecf39c..4557560779ed4eab46d349f6234e3a4b45195d20 100644 (file)
@@ -2465,6 +2465,8 @@ type_of (tree r, reflect_kind kind)
     }
   else if (TREE_CODE (r) == FIELD_DECL && DECL_BIT_FIELD_TYPE (r))
     r = DECL_BIT_FIELD_TYPE (r);
+  else if (TREE_CODE (r) == FUNCTION_DECL)
+    r = static_fn_type (r);
   else
     r = TREE_TYPE (r);
   return strip_typedefs (r);
index 29567918dc2eaba9e0bbbc80884774e203d0aceb..982b6202c7bab2e1856f1979ea0336a037cda32e 100644 (file)
@@ -25,7 +25,5 @@ g ()
 {
   constexpr auto fInfo = foo<F>()[0];
   using fType = [:type_of(fInfo):];
-  // TODO Should work: non-const non-volatile member functions have ordinary
-  // function types.
-  //static_assert (std::same_as<fType, auto(int)->void>);
+  static_assert (std::same_as<fType, auto(int)->void>);
 }