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

            Bug ID: 115722
           Summary: GCC uses old closure type when using as default
                    argument instead of using new closure type each time
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jlame646 at gmail dot com
  Target Milestone: ---

The following program output `12` instead of `11`. The output `11` is expected
because as per [dcl.fct.default] "default argument is evaluated each time the
function is called with no argument for the corresponding parameter" and also
the type of a lambda expression is unique each time. Demo
https://godbolt.org/z/fM7Yxx7oz

```
#include <iostream>

int foo(int x = [](){ static int x = 0; return ++x; }()) { return x; };

int main() {
    std::cout << foo() << foo(); // 12
}
```

Reply via email to