[Bug c++/124921] New: Some inconsistencies with reflection on functions (passing function as argument)

uchanahome8 at gmail dot com gcc-bugzilla@gcc.gnu.org
Sat Apr 18 08:23:01 GMT 2026


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124921

            Bug ID: 124921
           Summary: Some inconsistencies with reflection on functions
                    (passing function as argument)
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: uchanahome8 at gmail dot com
  Target Milestone: ---

Consider the following example: https://godbolt.org/z/sTEzfMPMq.

```
#include <meta>

void f1(int, char);

struct X {
    void f2(int);
};

template <typename T>
consteval auto get_fn_param_count(T) {
    constexpr static auto r = ^^T;
    static_assert(!std::meta::is_function(std::meta::remove_pointer(r)));
    static_assert(!std::meta::is_function(r));
    //return std::meta::parameters_of(r).size(); <- error
    return std::meta::parameters_of(std::meta::remove_pointer(r)).size();
}

template <typename T>
consteval auto get_mem_param_count(T) {
    constexpr static auto r = ^^T;
    static_assert(!std::meta::is_function(std::meta::remove_pointer(r)));
    static_assert(!std::meta::is_function(r));
    return std::meta::parameters_of(std::meta::remove_pointer(r)).size();
}

int main() {
    constexpr static auto mem1_count = std::meta::parameters_of(^^f1).size();
    constexpr static auto mem2_count =
std::meta::parameters_of(^^X::f2).size();
    constexpr static auto mem3_count = get_fn_param_count(f1);
    constexpr static auto mem4_count = get_fn_param_count(&f1);
    constexpr static auto mem5_count = get_mem_param_count(&X::f2);
    return 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, but in
get_fn_param_count, static_asserts and return statement are in a contradiction.

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?

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.


More information about the Gcc-bugs mailing list