llvm / llvm/llvm-project

[clang-format] Unexpected alignment of variable declarations when function arguments do not fit on a single line

Open
#187,987 3 comments 0 reactions 0 assignees View on GitHub
clang-format
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

With `AlignConsecutiveAssignments` set as follows:

```yaml
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: true
```

I'm seeing unexpected alignment of assignments whenever the function argument list oveflows into the next line. This happens regardless of the value of `BinPackArguments` or `AllowAllArgumentsOnNextLine`. Here's a test file that reproduces it.

```c++
void find(const char* zValue)
{
// This is expected
NAME_AND_VALUE key = {zValue};
void* pResult = bsearch(&key, 0, 1, sizeof(NAME_AND_VALUE), name_and_value_compare, other_function);

// This is unexpected
NAME_AND_VALUE key2 = {zValue};
void* pResult = bsearch(&key2, 0, 1, sizeof(NAME_AND_VALUE), name_and_value_compare,
other_function_with_longer_name);
}
```

This is not what I'd expect to happen as `AlignConsecutiveAssignments: false` should never align assignments. Am I missing some other obvious configuration value that's causing this? I tested this with both the `main` branch as well as clang-format 21.1.8 from Fedora 43.

Attached is the configuration that I used.

[clang-format.txt](https://github.com/user-attachments/files/26175704/clang-format.txt)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.