Author: mydeveloperday Date: 2021-11-25T08:30:31Z New Revision: 72e4f4a2a117f97118692857d91210fc62c066b0
URL: https://github.com/llvm/llvm-project/commit/72e4f4a2a117f97118692857d91210fc62c066b0 DIFF: https://github.com/llvm/llvm-project/commit/72e4f4a2a117f97118692857d91210fc62c066b0.diff LOG: [clang-format] [PR47936] AfterControlStatement: MultiLine breaks AllowShortFunctionsOnASingleLine 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 Added: Modified: clang/lib/Format/UnwrappedLineFormatter.cpp clang/unittests/Format/FormatTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 299536cd806eb..516b1bcac314c 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -676,7 +676,7 @@ class LineJoiner { // { <-- 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; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 8c8d7a465c795..096d6a32ecfce 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits