[clang] a0b1c23 - [clang-format] Currectly handle PCIS_CurrentLine with no column limit

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 6 12:14:31 PDT 2023


Author: Owen Pan
Date: 2023-08-06T12:14:23-07:00
New Revision: a0b1c235afab4743cf31e4ac4509120d3c156e60

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

LOG: [clang-format] Currectly handle PCIS_CurrentLine with no column limit

Fixes #63519.

Differential Revision: https://reviews.llvm.org/D157179

Added: 
    

Modified: 
    clang/lib/Format/ContinuationIndenter.cpp
    clang/unittests/Format/FormatTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 0ca297a5f95768..6b9b5aca7a364a 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1437,6 +1437,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
     if (Style.PackConstructorInitializers > FormatStyle::PCIS_BinPack) {
       CurrentState.AvoidBinPacking = true;
       CurrentState.BreakBeforeParameter =
+          Style.ColumnLimit > 0 &&
           Style.PackConstructorInitializers != FormatStyle::PCIS_NextLine &&
           Style.PackConstructorInitializers != FormatStyle::PCIS_NextLineOnly;
     } else {

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 1a1109f281b442..3d20163973d749 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -7758,6 +7758,13 @@ TEST_F(FormatTest, AllowAllConstructorInitializersOnNextLine) {
                "    aaaaaaaaaaaaaaaaaaaa(a),\n"
                "    bbbbbbbbbbbbbbbbbbbbb(b) {}",
                Style);
+
+  Style = getLLVMStyleWithColumns(0);
+  Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
+  verifyFormat("Foo(Bar bar, Baz baz) : bar(bar), baz(baz) {}", Style);
+  verifyNoChange("Foo(Bar bar, Baz baz)\n"
+                 "    : bar(bar), baz(baz) {}",
+                 Style);
 }
 
 TEST_F(FormatTest, AllowAllArgumentsOnNextLine) {


        


More information about the cfe-commits mailing list