<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/151844>151844</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang Format] Incorrect format for `for` loops when `AlignAfterOpenBracket` is `BlockIndent`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
szdytom
</td>
</tr>
</table>
<pre>
Clang Format doesn't respect its `AlignAfterOpenBracket` options when formatting multi-line for loops.
Here is a piece of code it produces when `AlignAfterOpenBracket` is set to `BlockIndent`
```cpp
void SmoothenMountainsPass::smoothen_mountains(
TileMap &tilemap, std::uint32_t step_i
) {
std::vector<std::pair<TilePos, Tile>> replacements;
for (std::uint8_t chunk_x = 0; chunk_x < tilemap.get_size(); ++chunk_x) {
for (std::uint8_t chunk_y = 0; chunk_y < tilemap.get_size();
++chunk_y) {
for (std::uint8_t local_x = 0; local_x < Chunk::size; ++local_x) {
for (std::uint8_t local_y = 0; local_y < Chunk::size;
++local_y) {
TilePos pos{chunk_x, chunk_y, local_x, local_y};
smoothen_mountains_tile(tilemap, pos, step_i, replacements);
}
}
}
}
}
```
The function parameter's format is OK, but the for loops aren't, it should be something like:
```cpp
void SmoothenMountainsPass::smoothen_mountains(
TileMap &tilemap, std::uint32_t step_i
) {
std::vector<std::pair<TilePos, Tile>> replacements;
for (std::uint8_t chunk_x = 0; chunk_x < tilemap.get_size(); ++chunk_x) {
for (std::uint8_t chunk_y = 0; chunk_y < tilemap.get_size();
++chunk_y
) {
for (std::uint8_t local_x = 0; local_x < Chunk::size; ++local_x) {
for (std::uint8_t local_y = 0; local_y < Chunk::size;
++local_y
) {
TilePos pos{chunk_x, chunk_y, local_x, local_y};
smoothen_mountains_tile(tilemap, pos, step_i, replacements);
}
}
}
}
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsVsGO4zYPfhrlQk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