[clang] 1f01269 - [clang-format] Fix alignment in presence of template functions (#68029)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 3 06:35:35 PDT 2023
Author: Björn Schäpers
Date: 2023-10-03T15:35:30+02:00
New Revision: 1f0126902876cb42a7502047e62bdf512fd96b02
URL: https://github.com/llvm/llvm-project/commit/1f0126902876cb42a7502047e62bdf512fd96b02
DIFF: https://github.com/llvm/llvm-project/commit/1f0126902876cb42a7502047e62bdf512fd96b02.diff
LOG: [clang-format] Fix alignment in presence of template functions (#68029)
Fixes #68102.
Added:
Modified:
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index 762729d1c4166a5..2cbde3da212ec65 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -372,9 +372,10 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
return true;
}
- // Continued function call
+ // Continued (template) function call.
if (ScopeStart > Start + 1 &&
- Changes[ScopeStart - 2].Tok->is(tok::identifier) &&
+ Changes[ScopeStart - 2].Tok->isOneOf(tok::identifier,
+ TT_TemplateCloser) &&
Changes[ScopeStart - 1].Tok->is(tok::l_paren) &&
Changes[ScopeStart].Tok->isNot(TT_LambdaLSquare)) {
if (Changes[i].Tok->MatchingParen &&
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 63ef294ce9d2949..246de2f89fccc9d 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -18525,12 +18525,17 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) {
" a_longer_name_for_wrap}};",
Alignment);
- Alignment.ColumnLimit = 60;
+ Alignment = getLLVMStyleWithColumns(60);
+ Alignment.AlignConsecutiveAssignments.Enabled = true;
verifyFormat("using II = typename TI<T, std::tuple<Types...>>::I;\n"
"using I = std::conditional_t<II::value >= 0,\n"
" std::ic<int, II::value + 1>,\n"
" std::ic<int, -1>>;",
Alignment);
+ verifyFormat("SomeName = Foo;\n"
+ "X = func<Type, Type>(looooooooooooooooooooooooong,\n"
+ " arrrrrrrrrrg);",
+ Alignment);
}
TEST_F(FormatTest, AlignConsecutiveBitFields) {
More information about the cfe-commits
mailing list