[clang] [clang-format] Fix alignment in presence of template functions (PR #68029)
Björn Schäpers via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 2 13:19:27 PDT 2023
https://github.com/HazardyKnusperkeks created https://github.com/llvm/llvm-project/pull/68029
None
>From 435592764243b0c70857dc7c340046ee3dc50ac9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= <bjoern at hazardy.de>
Date: Mon, 2 Oct 2023 22:12:19 +0200
Subject: [PATCH] [clang-format] Fix alignment in presence of template
functions
---
clang/lib/Format/WhitespaceManager.cpp | 5 +++--
clang/unittests/Format/FormatTest.cpp | 7 ++++++-
2 files changed, 9 insertions(+), 3 deletions(-)
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