[PATCH] D158505: [clang-format] Fix weird handling of AfterColon

Björn Schäpers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 22 04:20:29 PDT 2023


HazardyKnusperkeks created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, owenpan, MyDeveloperDay.
HazardyKnusperkeks requested review of this revision.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158505

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


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7950,6 +7950,11 @@
   verifyFormat("template <typename T>\n"
                "Constructor() : Initializer(FitsOnTheLine) {}",
                getStyleWithColumns(Style, 50));
+  verifyFormat(
+      "Class::Class(int some, int arguments, int loooooooooooooonoooooog,\n"
+      "             int mooooooooooooore) noexcept :\n"
+      "    Super{some, arguments}, Member{5}, Member2{2} {}",
+      Style);
   Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
   verifyFormat(
       "SomeClass::Constructor() :\n"
@@ -7987,8 +7992,8 @@
       "    aaaaaaaaaaaaaaa(aaaaaaaaaaaa) {}",
       Style);
   verifyFormat("Constructor(aaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
-               "            aaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) :\n"
-               "    aaaaaaaaaa(aaaaaa) {}",
+               "            aaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) : "
+               "aaaaaaaaaa(aaaaaa) {}",
                Style);
 
   verifyFormat("Constructor() :\n"
Index: clang/lib/Format/ContinuationIndenter.cpp
===================================================================
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1451,6 +1451,8 @@
     CurrentState.NestedBlockIndent = CurrentState.Indent;
     if (Style.PackConstructorInitializers > FormatStyle::PCIS_BinPack)
       CurrentState.AvoidBinPacking = true;
+    else
+      CurrentState.BreakBeforeParameter = false;
   }
   if (Current.is(TT_InheritanceColon)) {
     CurrentState.Indent =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158505.552310.patch
Type: text/x-patch
Size: 1722 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230822/e9017358/attachment.bin>


More information about the cfe-commits mailing list