From: Marek Polacek Date: Wed, 4 Feb 2026 16:31:02 +0000 (-0500) Subject: c++/reflection: fix type_of for member fns [PR123934] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=507ea25cf2e18bba38e28ab7b57cc725895cb067;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc index 624414e2346..4557560779e 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 29567918dc2..982b6202c7b 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()[0]; using fType = [:type_of(fInfo):]; - // TODO Should work: non-const non-volatile member functions have ordinary - // function types. - //static_assert (std::same_asvoid>); + static_assert (std::same_asvoid>); }