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

    <tr>
        <th>Summary</th>
        <td>
            clang 17: variable becomes const after template lambda is invoked
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    LLVM/clang 17 (772e37f8930724eaaa496ae62fabb8ae288b4086)

Preprocessed source (compile with `clang++ -std=c++20` is sufficient):
[output.zip](https://github.com/llvm/llvm-project/files/10923651/output.zip)

The error :

```
C:/dev/score/3rdparty/avendish/include/avnd/wrappers/audio_channel_manager.hpp:231:7: error: cannot assign to variable 'i' with const-qualified type 'const int'
    i = 4;
    ~ ^

[... skipping useless template instantations ...]

C:/dev/score/3rdparty/avendish/include/avnd/wrappers/audio_channel_manager.hpp:218:9: note: variable 'i' declared const here
    int i = 0;
 ~~~~^~~~~
```

the offending code looks like this: (starting from line 360450 in the preprocessed .cpp)

```c++
    int i = 0;
 i = 1; // ok
    
    std::invoke([this, &i] { i++; }); // ok
    i = 2; // ok
    
    auto& inputs = avnd::get_inputs(eff);

 in_refl::for_all(inputs, [this, &i](auto& p) { }); // ok
    i = 3; // ok

    in_refl::for_all(inputs, [this, &i]<avnd::audio_port P>(P& p) { }); // ok

    i = 4; // from this point "i" is const and the code does not compile

```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VU-P27gP_TTMhaghU4n_HHJIJvWpP6CHH_Y6kG06VkeRvJI8Rfcwn30hO9NktoNte1kgkGKJIh-f-CgVgj5b5j3sjrA7bdQcR-f3Xzo27DX7Tev6b_tPn_74H1DTGWXPmJcIVJUlsSyHqpaipC0rpbZ1obigQbVtpZiqqt2KqgCqQZxAHNbxs-fJu45D4B6Dm33HyVvnLpM2jF91HBEKs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