<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/97256>97256</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang uses old closure type when using as default argument instead of using new closure type each time
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ranaanoop
      </td>
    </tr>
</table>

<pre>
    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 as per [expr.prim.lambda.closure]  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
}
```

Note that at [cppinsights](https://cppinsights.io/s/abca4605), clang does create a new class type each time but still produces the output `12` instead of `11`. So creating a new class type each time but still using the old one seems odd/wrong. Gcc also produces the output `12`. 

The output should be `11` afaik as a new class-type is created each time.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVE2P4zYP_jXMhRjDluMkPvgwmbx5T-2lvfTISEysVpZcfcxk99cXkr2bYLooFhh4Yvoh-fDhB4Wgb5Z5gO4I3WlDKY7OD54skXVu3lyc-jL8PjJenTHuQ9sbzt7dPE3oUpxTRNjVjYBdjdqGyKTQXYutgV1dYXZ9AjYFGJDvM8vICi8sKQVGCjizR-iOSprqKmOl-ErJROhOCEKsb0j-lia2sQR5J5MoR2GSI0Y9McZMNVkZtbMZI8kYVvih44jWPdyvzhesdN5zmJ1VpTTyNHFkD0IgWfVEi--zr2avp8rQdFFUSeNC8pz5lUjxy8y5dsIFkGv0HMJKJFn9d-IH0yoHPfHkoDuBOIwxzgHaVxBnEOebUxdnYuX8DcT5K4jz9Zf9H_f73n0F0VdQn6B-XZ-7ev1bXkWrrTRJMUL7pl2InmmC9n_PProI4EAc8q87QnvCZQBAHED0sD9iiBS1xAeghvaInmPyFkEcQRzv2QL7b06ix-y4Qr5_bI-fU0-k7eKTHRY7ImKIKivQvkqXx6V9g_Zt5VmwnwwlQZELG7Hm2J9-rEp5_upiHhCKSDHXK-dZ26BvYww_asLT50o7EOcA4kwXSdtd3ZWC31AasjdUjgNKzxQZCS1_ZHsIy0g8ZvOSIoaojckrpJLkUAbnp_boN7ckyFP6UylSyNAS3yh0ljEwTwGdUiDOH97ZW4X_lxLJBPefhCp8FvFpocPokskr_FhtupL-K2_NE8eXwlF_U-hpW6uNGlrVtz1teGj2TX9omr49bMah2THvtnV96LmRkvutuFzbuqGWRNd2_XajB1GLbb2vm7prRXOouq04yFaRatqtUAcF25on0qYy5n3Ki7TRISQe-r3odhtDFzahXD0hShNBiHwA_ZDxL5d0C7CtjQ4xPCJEHQ0Pb6XnKXAo0q53YOnEx8h2lZ4C_vtoPVq7gBaRngJ812aTvBk-XQUdx3SppJtAnDOp9d_L7N2fLCOIc6kxz-lS5vsg_gkAAP__s9zbgg">