Skip to content

Commit 6fee149

Browse files
committed
Simplify and add more tests
1 parent 3d4d9d7 commit 6fee149

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,20 +464,18 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
464464
if (i + 1 != Changes.size())
465465
Changes[i + 1].PreviousEndOfTokenColumn += Shift;
466466

467-
// If PointerAlignment is PAS_Right, keep *s or &s next to the token
467+
// If PointerAlignment is PAS_Right, keep *s or &s next to the token,
468+
// except if the token is equal, then a space is needed.
468469
if ((Style.PointerAlignment == FormatStyle::PAS_Right ||
469470
Style.ReferenceAlignment == FormatStyle::RAS_Right) &&
470-
CurrentChange.Spaces != 0) {
471+
CurrentChange.Spaces != 0 && !CurrentChange.Tok->is(tok::equal)) {
471472
const bool ReferenceNotRightAligned =
472473
Style.ReferenceAlignment != FormatStyle::RAS_Right &&
473474
Style.ReferenceAlignment != FormatStyle::RAS_Pointer;
474475
for (int Previous = i - 1;
475476
Previous >= 0 &&
476477
Changes[Previous].Tok->getType() == TT_PointerOrReference;
477478
--Previous) {
478-
// Don't align function default argument using return type maximum size
479-
if (Changes[Previous + 1].Tok->is(tok::equal))
480-
continue;
481479
assert(Changes[Previous].Tok->isPointerOrReference());
482480
if (Changes[Previous].Tok->isNot(tok::star)) {
483481
if (ReferenceNotRightAligned)

clang/unittests/Format/FormatTest.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19056,7 +19056,8 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
1905619056
verifyFormat("int a(int x);\n"
1905719057
"double b();",
1905819058
Alignment);
19059-
verifyFormat("int a(const Test & = Test());\n"
19059+
verifyFormat("int a(int &count, SomeType &foo, const Test & = Test());\n"
19060+
"int a2(int &foo, const Test &name = Test());\n"
1906019061
"double b();",
1906119062
Alignment);
1906219063
verifyFormat("struct Test {\n"
@@ -19280,7 +19281,7 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
1928019281
"int foobar;",
1928119282
AlignmentLeft);
1928219283

19283-
verifyFormat("int a(const Test& = Test());\n"
19284+
verifyFormat("int a(int& count, SomeType& foo, const Test& = Test());\n"
1928419285
"double b();",
1928519286
AlignmentLeft);
1928619287

@@ -19344,6 +19345,10 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
1934419345
"int foobar;",
1934519346
AlignmentMiddle);
1934619347

19348+
verifyFormat("int a(int & count, SomeType & foo, const Test & = Test());\n"
19349+
"double b();",
19350+
AlignmentMiddle);
19351+
1934719352
Alignment.AlignConsecutiveAssignments.Enabled = false;
1934819353
Alignment.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign;
1934919354
verifyFormat("#define A \\\n"

0 commit comments

Comments
 (0)