[clang] [clang-format] Fix alignment in presence of template functions (PR #68029)
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?= 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>::I;\n" "using I = std::conditional_t= 0,\n" " std::ic,\n" " std::ic>;", Alignment); + verifyFormat("SomeName = Foo;\n" + "X= func(long,\n" + "arrg);", + Alignment); } TEST_F(FormatTest, AlignConsecutiveBitFields) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix alignment in presence of template functions (PR #68029)
owenca wrote: Can you add an issue to show the incorrect format before this patch? https://github.com/llvm/llvm-project/pull/68029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix alignment in presence of template functions (PR #68029)
@@ -18525,12 +18525,17 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) { " a_longer_name_for_wrap}};", Alignment); - Alignment.ColumnLimit = 60; + Alignment = getLLVMStyleWithColumns(60); + Alignment.AlignConsecutiveAssignments.Enabled = true; owenca wrote: Is this necessary? If `AlignConsecutiveAssignments` is already on, you can use `EXPECT_TRUE` instead. https://github.com/llvm/llvm-project/pull/68029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix alignment in presence of template functions (PR #68029)
https://github.com/mydeveloperday approved this pull request. https://github.com/llvm/llvm-project/pull/68029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix alignment in presence of template functions (PR #68029)
@@ -18525,12 +18525,17 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) { " a_longer_name_for_wrap}};", Alignment); - Alignment.ColumnLimit = 60; + Alignment = getLLVMStyleWithColumns(60); + Alignment.AlignConsecutiveAssignments.Enabled = true; owenca wrote: Nvm. https://github.com/llvm/llvm-project/pull/68029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix alignment in presence of template functions (PR #68029)
https://github.com/owenca approved this pull request. https://github.com/llvm/llvm-project/pull/68029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix alignment in presence of template functions (PR #68029)
https://github.com/HazardyKnusperkeks edited https://github.com/llvm/llvm-project/pull/68029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix alignment in presence of template functions (PR #68029)
HazardyKnusperkeks wrote: > Can you add an issue to show the incorrect format before this patch? Done. https://github.com/llvm/llvm-project/pull/68029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix alignment in presence of template functions (PR #68029)
https://github.com/HazardyKnusperkeks closed https://github.com/llvm/llvm-project/pull/68029 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits