[Bug c++/124921] Some inconsistencies with reflection on functions (passing function as argument)
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sat Apr 18 11:16:23 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124921
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Aakash Gupta from comment #0)
> 1. As per 15.1 of
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3096r12.pdf,
> std::meta::parameters_of is applicable to function types,
Yes.
> but in
> get_fn_param_count, static_asserts and return statement are in a
> contradiction.
I don't see any. The 2 static_asserts are right, neither remove_pointer(r) nor
r is a function, the former is a function type (so
static_assert(is_function_type(remove_pointer(r)));
is valid), while static_assert(is_pointer_type(r) && !is_function_type(!r));
is also valid. So, parameters_of(remove_pointer(r)) is valid, while
parameters_of(r) is not.
> 2. Uncommenting `return std::meta::parameters_of(r).size();` results in
> compiler error: `reflection does not represent a function or function type`.
> Doesn't seem correct, because `throw
> std::runtime_error(std::string(std::meta::display_string_of(^^T)));` in
> `get_fn_param_count` gives `void (*)(int, char)`, which is a function type?
Nope, void (*)(int, char) is not a function type, it is a pointer to function
type.
> 3. [Query] How can I make get_mem_param_count compile? I tried many things
> but can't find a way to compile that method.
r reflects in that case pointer-to-member type, so
static_assert(is_member_pointer(r) && is_member_function_pointer_type(r)) is
valid.
I think C++26 doesn't have metafunctions to inspect pointer to member types
(e.g. for pointer-to-member-object get the pointed to type or the associated
class, for pointer-to-member-function get the function type of the method,
associated class, etc.
More information about the Gcc-bugs
mailing list