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

            Bug ID: 129098
           Summary: wrong call operator returned by members_of() for two
                    templated lambdas defined in different functions
           Product: gcc
           Version: 16.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alessandro.marzocchi at gmail dot com
  Target Milestone: ---

Created attachment 66309
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66309&action=edit
Example triggering the misbehaviour. static_assert fails in testB()

If using members_of() on the closure type of two lambdas defined in different
functions GCC will return for the second one the template call operator
belonging to the first one. The issue occurs only with lambdas having a
template call operator, either through an explicit template parameter
(<typename T>) or an auto parameter. 

The behaviours seems to be triggered whenever a pattern similar to:
void func1() {
    auto lambda=[]<typename T>(T in) { ...; };
    constexpr auto x=define_static_array(members_of(^^decltype(lambda),
std::meta::access_context::unprivileged()));
}
void func2() {
    auto lambda=[]<typename T>(T in) { ...; };
    constexpr auto x=define_static_array(members_of(^^decltype(lambda),
std::meta::access_context::unprivileged()));
}

It does not matter if the members_of is called directly in the function or in a
helper function, for example a similar pattern still triggers the bug:

template <std::meta::info data> void helper() {
    constexpr auto x=define_static_array(members_of(data,
std::meta::access_context::unprivileged()));
}
void func1() {
    auto lambda=[]<typename T>(T in) { ...; };
    helper(^^decltype(lambda));
}
void func2() {
    auto lambda=[]<typename T>(T in) { ...; };
    helper(^^decltype(lambda));
}

The behaviour is the same in GCC versions 16.1, 16.2 and trunk in both (at
least X86 and ARM64), tested in godbolt. Attached is a minimal example that
triggers the misbehaviour, must be compiled with -std=c++26 -freflection.

I'm providing the same source in godbolt:
https://godbolt.org/z/xGab6hM5z
and a slightly more complex example closer to the code that I originally use
wrote:
https://godbolt.org/z/WE98TcT1x

Reply via email to