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

            Bug ID: 116714
           Summary: [14 Regression] Inconsistent lambda type inference in
                    function template instance
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ted at lyncon dot se
  Target Milestone: ---

The lambda type `type` is here used to instantiate two objects, i1 and i2. They
are clearly of the same type since `std::is_same_v<decltype(i1), decltype(i2)>`
is `true` and they also use the same `static` variable, `x`.

However, `std::is_same_v<type, type>` is `false`:
```
#include <iostream>
#include <type_traits>

template<class = void> // remove this and all passes
void foo() {
    using type = decltype([](){ static int x = 0; return ++x; });
    type i1;
    type i2;

    // passes:
    static_assert(std::is_same_v<decltype(i1), decltype(i2)>);

    // does not pass:
    static_assert(std::is_same_v<type, type>);

    // prints 12 if static_assert above is removed:
    std::cout << i1() << i2() << '\n';
};

int main() {    
    foo();
}
```

This seems to be a regression since gcc 13

Reply via email to