Skip to content

Commit 1f01269

Browse files
[clang-format] Fix alignment in presence of template functions (#68029)
Fixes #68102.
1 parent 1482106 commit 1f01269

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,10 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
372372
return true;
373373
}
374374

375-
// Continued function call
375+
// Continued (template) function call.
376376
if (ScopeStart > Start + 1 &&
377-
Changes[ScopeStart - 2].Tok->is(tok::identifier) &&
377+
Changes[ScopeStart - 2].Tok->isOneOf(tok::identifier,
378+
TT_TemplateCloser) &&
378379
Changes[ScopeStart - 1].Tok->is(tok::l_paren) &&
379380
Changes[ScopeStart].Tok->isNot(TT_LambdaLSquare)) {
380381
if (Changes[i].Tok->MatchingParen &&

clang/unittests/Format/FormatTest.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18525,12 +18525,17 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) {
1852518525
" a_longer_name_for_wrap}};",
1852618526
Alignment);
1852718527

18528-
Alignment.ColumnLimit = 60;
18528+
Alignment = getLLVMStyleWithColumns(60);
18529+
Alignment.AlignConsecutiveAssignments.Enabled = true;
1852918530
verifyFormat("using II = typename TI<T, std::tuple<Types...>>::I;\n"
1853018531
"using I = std::conditional_t<II::value >= 0,\n"
1853118532
" std::ic<int, II::value + 1>,\n"
1853218533
" std::ic<int, -1>>;",
1853318534
Alignment);
18535+
verifyFormat("SomeName = Foo;\n"
18536+
"X = func<Type, Type>(looooooooooooooooooooooooong,\n"
18537+
" arrrrrrrrrrg);",
18538+
Alignment);
1853418539
}
1853518540

1853618541
TEST_F(FormatTest, AlignConsecutiveBitFields) {

0 commit comments

Comments
 (0)