[clang] ca0aa53 - [clang-format] Handle Template Arguments with AlignConsecutiveXX

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 29 13:00:05 PDT 2023


Author: Björn Schäpers
Date: 2023-08-29T21:59:44+02:00
New Revision: ca0aa533656ceb806d2744c38766f70c317f1053

URL: https://github.com/llvm/llvm-project/commit/ca0aa533656ceb806d2744c38766f70c317f1053
DIFF: https://github.com/llvm/llvm-project/commit/ca0aa533656ceb806d2744c38766f70c317f1053.diff

LOG: [clang-format] Handle Template Arguments with AlignConsecutiveXX

This fixes https://github.com/llvm/llvm-project/issues/64928.

Differential-Revision: https://reviews.llvm.org/D158945

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 04048aedb3e392..6951c2a113a923 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -425,6 +425,10 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
           return true;
         }
 
+        // Continued template parameter.
+        if (Changes[ScopeStart - 1].Tok->is(TT_TemplateOpener))
+          return true;
+
         return false;
       };
 

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index c1368c947af1ef..0d8bc41265199b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -18726,6 +18726,13 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) {
                "                    {a_longer_name_for_wrap,\n"
                "                     a_longer_name_for_wrap}};",
                Alignment);
+
+  Alignment.ColumnLimit = 60;
+  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);
 }
 
 TEST_F(FormatTest, AlignConsecutiveBitFields) {


        


More information about the cfe-commits mailing list