<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/136541>136541</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format] Regression: AlignConsecutiveDeclarations introduces invalid spacing in using declarations with overloaded operators
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kust1011
</td>
</tr>
</table>
<pre>
### Description
In Clang-format versions 20.1.1 and 20.1.2, enabling `AlignConsecutiveDeclarations` causes incorrect formatting of `using` declarations involving overloaded operators. Specifically, an extra space is inserted between the scope resolution operator `::` and the overloaded operator name, resulting in invalid C++ syntax.
#### Minimal Example
**Input:**
```cpp
#include <vector>
void test1() {
using std::operator==;
std::vector<int> v;
}
void test2() {
using std::operator==;
std::vector<int> v;
}
```
**Formatted Output with Clang-format 20.1.1 / 20.1.2:**
```cpp
#include <vector>
void test1() {
using std:: operator==;
std::vector<int> v;
}
void test2() {
using std::operator==;
std::vector<int> v;
}
```
In `test1()`, Clang-format inserts extra whitespace between `::` and `operator==`, producing a non-standard formatting that may be misleading or undesirable in production code. This behavior is triggered when the `using` declaration is followed by another declaration that enables alignment logic (e.g., `std::vector<int> v;`) under the `AlignConsecutiveDeclarations` setting. While the resulting code is still syntactically valid, the formatting contradicts conventional C++ style and may degrade readability or tooling reliability.
#### Style Configuration
```yaml
BasedOnStyle: LLVM
SpaceBeforeParens: Never
SpacesInAngles: Never
AlignConsecutiveDeclarations: true
```
#### Analysis
This issue appears to stem from the alignment logic introduced by `AlignConsecutiveDeclarations`. When multiple declarations are present, Clang-format attempts to align them, treating `operator==` in the `using` declaration as a field to align. This leads to the insertion of spaces within the `using` declaration, breaking the syntax.
Notably, this behavior is a regression from Clang-format 19.1.7, which correctly preserved or corrected the formatting regardless of context.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUVktv4zYQ_jX0ZR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