<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/67897>67897</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`AlignOperands: DontAlign` mostly ignored for `<<`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
pcolby
</td>
</tr>
</table>
<pre>
Hopefully I'm just misunderstanding something here, but I cannot get clang-format (at least v15, v16 and v17) to obey `AlignOperands: DontAlign` for `<<` operators.
Probably related (though not exactly the same scenarios) as:
* https://github.com/llvm/llvm-project/issues/44363; and
* https://github.com/llvm/llvm-project/issues/59797.
Consider this clang-format style:
```
---
Language: Cpp
AlignOperands: DontAlign
...
```
And this example source:
```cpp
// Incorrectly ignores `AlignOperands: DontAlign`
qCWarning(lc).noquotex() << a << b << c << d << e << f << g << h << i << j << k << l;
// Correctly (?) uses ContinuationIndentWidth.
qCWarning(lc).noquotexx() << a << b << c << d << e << f << g << h << i << j << k << l;
// Incorrectly ignores `AlignOperands: DontAlign`
qCWarning(lc).noquotex() << aa << bb << cc << dd << ee << ff << gg << hh << ii << jj << kk;
// Correctly (?) uses ContinuationIndentWidth.
qCWarning(lc).noquotexx() << aa << bb << cc << dd << ee << ff << gg << hh << ii << jj << kk;
// Incorrectly ignores `AlignOperands: DontAlign`
qCWarning(lc).noquotex() << aaa << bbb << ccc << ddd << eee << fff << ggg << hhh << iii << jjj;
// Correctly (?) uses ContinuationIndentWidth.
qCWarning(lc).noquotexx() << aaa << bbb << ccc << ddd << eee << fff << ggg << hhh << iii << jjj;
// Incorrectly ignores `AlignOperands: DontAlign`
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx << aaa << bbb << ccc << ddd << eee << fff << ggg << hhh << iii << jjj;
// Correctly (?) uses ContinuationIndentWidth.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx << aaa << bbb << ccc << ddd << eee << fff << ggg << hhh << iii << jjj;
// Correctly (?) uses ContinuationIndentWidth.
qCWarning(lc) + aaa + bbb + ccc + ddd + eee + fff + ggg + hhh + iii + jjj + kkk + lll;
// Correctly (?) uses ContinuationIndentWidth.
qCWarning(lc) >> aaa >> bbb >> ccc >> ddd >> eee >> fff >> ggg >> hhh >> iii >> jjj >> kkk;
```
The clang-formatted output is:
```cpp
// Incorrectly ignores `AlignOperands: DontAlign`
qCWarning(lc).noquotex() << a << b << c << d << e << f << g << h << i << j
<< k << l;
// Correctly (?) uses ContinuationIndentWidth.
qCWarning(lc).noquotexx()
<< a << b << c << d << e << f << g << h << i << j << k << l;
// Incorrectly ignores `AlignOperands: DontAlign`
qCWarning(lc).noquotex() << aa << bb << cc << dd << ee << ff << gg << hh << ii
<< jj << kk;
// Correctly (?) uses ContinuationIndentWidth.
qCWarning(lc).noquotexx()
<< aa << bb << cc << dd << ee << ff << gg << hh << ii << jj << kk;
// Incorrectly ignores `AlignOperands: DontAlign`
qCWarning(lc).noquotex() << aaa << bbb << ccc << ddd << eee << fff << ggg
<< hhh << iii << jjj;
// Correctly (?) uses ContinuationIndentWidth.
qCWarning(lc).noquotexx()
<< aaa << bbb << ccc << ddd << eee << fff << ggg << hhh << iii << jjj;
// Incorrectly ignores `AlignOperands: DontAlign`
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx << aaa << bbb << ccc << ddd << eee
<< fff << ggg << hhh << iii << jjj;
// Correctly (?) uses ContinuationIndentWidth.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
<< aaa << bbb << ccc << ddd << eee << fff << ggg << hhh << iii << jjj;
// Correctly (?) uses ContinuationIndentWidth.
qCWarning(lc) + aaa + bbb + ccc + ddd + eee + fff + ggg + hhh + iii + jjj +
kkk + lll;
// Correctly (?) uses ContinuationIndentWidth.
qCWarning(lc) >> aaa >> bbb >> ccc >> ddd >> eee >> fff >> ggg >> hhh >>
iii >> jjj >> kkk;
```
As you can see (or as I inerpret it), there are plenty of cases where the `<<` operators' operands are being wrapped, then aligned, despite the `AlignOperands: DontAlign`, but if the very first operand exceeds some (not consistent) length then the `DontAlign` is obeyed, and the `ContinuationIndentWidth` is used.
This appears to only affect `<<` operators. For example, `+` and `>>` are not affected, and seems to work as I would expect based on how I read the documentation.
Also, although I use a (real-world) example of `qCWarning(lc).noquote()`, the same happens if the first terminal is just some plain (not long enough) variable name too (the `x{42,43}` examples above).
The output above is from clang-format 17.0.2, but I get the same results (or very similar) with v15 and v16 too (haven't tested any other versions).
Thanks 😄
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcmctu4zoShp-G3hRiyPR94UXktDEBBphZDNBrSixJjClSTVJ2_PYDklJLOd25nO4kbhzDsMu6kP_Hn5ZKRWatKBXijixTsrybsNZV2uyaXMvsMsk0v-z-pRssWikvcE_ouoaH1jqohW0VR2MdU1yoEqyu0VU-qtAgoXvIWgf3kDOltIMSHeSSqfKm0KZmDgjdMAcSmXVwmi39CafZCpjicJqtCd2C06AzvABZJbdSlOo_DRqmuCXzW7jTyoWNZJVAoY0_iMz3_r1KQPsjnTZ2SpI7ktzGz_8anbFMXsCgZA65l-Aq3ZYVeIX4yHInL-AqBMtqBJujYkZo68Uw323XGr2FyrkmbKEHQg-lcFWbTXNdE3qQ8tR_3TRGP2DuCD0Ia1u0hB4Wi_lqTuapJ32P9pbb9Xb9hHOvlRUcDbhK2KeDbt1F4gASP1dJ9w4_b25uYvBvpsqWlf5w2DdN3PiCEWH_dDr9aavd2YpHUfjI6kYiWN2a_FlBed8rAEAcGbhXuTYGg1OiVNqgfXWCDI18239lRglVErqROaHbqdLfWu3wkdCNtznOIWB9kPVB3ge8D7APij4o-6DqA9EHD31w7ANJ5umYesS4_07oVc0PXlhr0cJeKydUy5zQ6l5xVO6r4K6avgXwjyL8JBcHyIFywBw4B9CBdEAdWAfYgfZ4ZR-vzPhZTo4wR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