[clang-format] [PR47936] AfterControlStatement: MultiLine breaks AllowShortFunctionsO...
authormydeveloperday <mydeveloperday@gmail.com>
Thu, 25 Nov 2021 08:30:31 +0000 (08:30 +0000)
committermydeveloperday <mydeveloperday@gmail.com>
Thu, 25 Nov 2021 08:30:31 +0000 (08:30 +0000)
https://bugs.llvm.org/show_bug.cgi?id=47936

Using the MultiLine setting for BraceWrapping.AfterControlStatement appears to disable AllowShortFunctionsOnASingleLine, even in cases without any control statements

Reviewed By: HazardyKnusperkeks, curdeius

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

clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp

index 299536cd806eb2b59995edce2ab5492cae7a4a21..516b1bcac314c13e36ddc8a9283cd717a3641b80 100644 (file)
@@ -676,7 +676,7 @@ private:
         // { <-- current Line
         //   baz();
         // }
-        if (Line.First == Line.Last &&
+        if (Line.First == Line.Last && Line.First->isNot(TT_FunctionLBrace) &&
             Style.BraceWrapping.AfterControlStatement ==
                 FormatStyle::BWACS_MultiLine)
           return 0;
index 8c8d7a465c7951175d3b2e082ef2c3b9ab5aa9ae..096d6a32ecfcee6e89fc48423d2e2bae32708a49 100644 (file)
@@ -2860,6 +2860,19 @@ TEST_F(FormatTest, MultiLineControlStatements) {
             "  baz();\n"
             "}",
             format("try{foo();}catch(...){baz();}", Style));
+
+  Style.BraceWrapping.AfterFunction = true;
+  Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_MultiLine;
+  Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
+  Style.ColumnLimit = 80;
+  verifyFormat("void shortfunction() { bar(); }", Style);
+
+  Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
+  verifyFormat("void shortfunction()\n"
+               "{\n"
+               "  bar();\n"
+               "}",
+               Style);
 }
 
 TEST_F(FormatTest, BeforeWhile) {