I've recently tried the ReferenceAlignment: Left option introduced in clang-format 13.
In combination with AlignConsecutiveDeclarations: true it produces a rather strange results:
ShortType & v1;
SomeLongerType & v2;
MuchMuchLongerType& v3;
The v3's & is aligned to the left, but the other two are aligned on the rightmost ampersand.
Is there a way for me to get this result instead:
ShortType& v1;
SomeLongerType& v2;
MuchMuchLongerType& v3;
There seems to be some interference between PointerAlignment and ReferenceAlignment. When they are both Left, I get the desired result. When the PointerAlignment is Right, I get the strange one.
$ echo "struct Test { ShortType& v1; SomeLongerType& v2; MuchMuchLongerType& v3;};" | clang-format-13 --style "{AlignConsecutiveDeclarations: true, PointerAlignment: Right, ReferenceAlignment: Left}"
struct Test {
ShortType & v1;
SomeLongerType & v2;
MuchMuchLongerType& v3;
};
$ echo "struct Test { ShortType& v1; SomeLongerType& v2; MuchMuchLongerType& v3;};" | clang-format-13 --style "{AlignConsecutiveDeclarations: true, PointerAlignment: Left, ReferenceAlignment: Left}"
struct Test {
ShortType& v1;
SomeLongerType& v2;
MuchMuchLongerType& v3;
};
Moreover, even when ReferenceAlignment is Right, the PointerAlignment still affects the result:
$ echo "struct Test { ShortType& v1; SomeLongerType& v2; MuchMuchLongerType& v3;};" | clang-format-13 --style "{AlignConsecutiveDeclarations: true, PointerAlignment: Left, ReferenceAlignment: Right}"
struct Test {
ShortType & v1;
SomeLongerType & v2;
MuchMuchLongerType &v3;
};
$ echo "struct Test { ShortType& v1; SomeLongerType& v2; MuchMuchLongerType& v3;};" | clang-format-13 --style "{AlignConsecutiveDeclarations: true, PointerAlignment: Right, ReferenceAlignment: Right}"
struct Test {
ShortType &v1;
SomeLongerType &v2;
MuchMuchLongerType &v3;
};
This may be a bug in clang-format, or it may be an expected behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With