https://gcc.gnu.org/g:507ea25cf2e18bba38e28ab7b57cc725895cb067

commit r16-7330-g507ea25cf2e18bba38e28ab7b57cc725895cb067
Author: Marek Polacek <[email protected]>
Date:   Wed Feb 4 11:31:02 2026 -0500

    c++/reflection: fix type_of for member fns [PR123934]
    
    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 <[email protected]>

Diff:
---
 gcc/cp/reflect.cc                       | 2 ++
 gcc/testsuite/g++.dg/reflect/type_of2.C | 4 +---
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc
index 624414e23466..4557560779ed 100644
--- a/gcc/cp/reflect.cc
+++ b/gcc/cp/reflect.cc
@@ -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);
diff --git a/gcc/testsuite/g++.dg/reflect/type_of2.C 
b/gcc/testsuite/g++.dg/reflect/type_of2.C
index 29567918dc2e..982b6202c7ba 100644
--- a/gcc/testsuite/g++.dg/reflect/type_of2.C
+++ b/gcc/testsuite/g++.dg/reflect/type_of2.C
@@ -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>);
 }

Reply via email to