Skip to content

[Clang Format] Incorrect format for for loops when AlignAfterOpenBracket is BlockIndent #151844

@szdytom

Description

@szdytom

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

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:

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);
				}
			}
		}
	}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions