<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58146>58146</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format] MAYBE BUG: Inline lambda will move following params, to the nowhere
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
florianbecker
</td>
</tr>
</table>
<pre>
Input:
```cpp
/* stl header */
#include <functional>
#include <iostream>
/* modern.cpp.core */
#include <Timer.h>
constexpr int intervallSeconds = 1;
constexpr int secondsToMilliseconds = 1000;
constexpr int exitSeconds = 15;
int main() {
int intervall = 1;
auto intervallTimer = vx::Timer();
intervallTimer.setInterval( [ &intervallTimer, &intervall ]() {
std::cout << "Intervall: " << intervall << std::endl;
intervall++;
if ( intervall >= exitSeconds ) {
intervallTimer.stop();
}
}, intervallSeconds * secondsToMilliseconds );
while ( true ) {
/* Leave the app run infinity */
if ( !intervallTimer.isRunning() ) {
break;
}
}
return EXIT_SUCCESS;
}
```
Will end like that:
```cpp
/* stl header */
#include <functional>
#include <iostream>
/* modern.cpp.core */
#include <Timer.h>
constexpr int intervallSeconds = 1;
constexpr int secondsToMilliseconds = 1000;
constexpr int exitSeconds = 15;
int main() {
int intervall = 1;
auto intervallTimer = vx::Timer();
intervallTimer.setInterval( [ &intervallTimer, &intervall ]() {
std::cout << "Intervall: " << intervall << std::endl;
intervall++;
if ( intervall >= exitSeconds ) {
intervallTimer.stop();
}
},
intervallSeconds * secondsToMilliseconds );
while ( true ) {
/* Leave the app run infinity */
if ( !intervallTimer.isRunning() ) {
break;
}
}
return EXIT_SUCCESS;
}
```
Workaround:
Define a function and do not write the lambda inline. Will keep the formatting.
```cpp
/* stl header */
#include <functional>
#include <iostream>
/* modern.cpp.core */
#include <Timer.h>
constexpr int intervallSeconds = 1;
constexpr int secondsToMilliseconds = 1000;
constexpr int exitSeconds = 15;
int main() {
int intervall = 1;
auto intervallTimer = vx::Timer();
using func = std::function<void( void )>;
const func runOnInterval = [ &intervallTimer, &intervall ]() {
std::cout << "Intervall: " << intervall << std::endl;
intervall++;
if ( intervall >= exitSeconds ) {
intervallTimer.stop();
}
};
intervallTimer.setInterval( runOnInterval, intervallSeconds * secondsToMilliseconds );
while ( true ) {
/* Leave the app run infinity */
if ( !intervallTimer.isRunning() ) {
break;
}
}
return EXIT_SUCCESS;
}
```
Tested on clang-format-15 and clang-format-14
My configuration:
[clang-format.txt](https://github.com/llvm/llvm-project/files/9709136/clang-format.txt)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztVkmPozgU_jVwsQqxZTtwyNajkrrUUle1ZuY0cuARPDE2sk1S9e_72YQUpFOtac2cRolIwG9fP7KTxVv2KJrWeMnSCzdeuPSmYXflTXOmxJ-8eEm04aQCWoAieLTEMzdhIudtAcRL1mUrcsOkoNxLtrcEmNRGAa3f2UMftUTzIkDXQS4V_MTRC6tBBdWVmVwKbeC1UYQJY7-gjpTzZ0BGoVFvQyIvWd0S1p3Mi3xinDM91AjD8AMleGVmZHxyEex-rVBNmfDiuRcviDcbcck4zKv4CKGtke9sl7KTOb7adiVLR-lMX_klV2qBBvN4pqAC8SYrLO50LOTF6xERpTbXgRP8aFN0_nPZGtsMvFAx7h1g75f23LOGCTrCxQCIgg_yHUTtxSt7jXglsaEPrW1tNUZNuFXkkeFzOYxsrgpnpbzZpj_Yx3h9Y4bsKtyelRtdOFWMgwvbqBY-Cu88_Z-BHoGYCghtGqJagd5LJph5Gy3CoBZeHF0lxvTXVggm9n3jPirIDrfw8LPkRxoKTKsE2f7x-PLX87f1evv8_J7rRbiHjqHu71gign0mnB1scvQONXeouUPNj1AzNPHR545G_xaNpDpQJVtRXFBoA5gVJkl6QCEU0aqQREhDToqZrgic1ruCYg04SgfEwdoBoHHMUqqaGoOJBndo-z9BW6uxp24ynMoFTfoOYQ2PkhV2-u2927rtwLnLtDOAK_RF9MDl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