diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index aed86c1fb9955..5edd981764f59 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -461,9 +461,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { getColumnLimit(State) || CurrentState.BreakBeforeParameter) && (!Current.isTrailingComment() || Current.NewlinesBefore > 0) && - (Style.AllowShortFunctionsOnASingleLine != FormatStyle::SFS_All || - Style.BreakConstructorInitializers != FormatStyle::BCIS_BeforeColon || - Style.ColumnLimit != 0)) { + (Style.BreakConstructorInitializers != FormatStyle::BCIS_BeforeColon || + Style.ColumnLimit > 0 || Current.NewlinesBefore > 0)) { return true; } diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 05c86db55641f..a1b551ae060f7 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -492,7 +492,8 @@ class AnnotatingParser { ProbablyFunctionType && CurrentToken->Next && (CurrentToken->Next->is(tok::l_paren) || (CurrentToken->Next->is(tok::l_square) && - Line.MustBeDeclaration))) { + (Line.MustBeDeclaration || + PrevNonComment->isTypeName(LangOpts))))) { OpeningParen.setType(OpeningParen.Next->is(tok::caret) ? TT_ObjCBlockLParen : TT_FunctionTypeLParen); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index eeb857a914b1a..e892f10433c55 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -14503,10 +14503,13 @@ TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) { FormatStyle DoNotMergeNoColumnLimit = NoColumnLimit; DoNotMergeNoColumnLimit.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; - verifyFormat("A()\n" - " : b(0) {\n" + verifyFormat("A() : b(0) {\n" "}", - "A():b(0){}", DoNotMergeNoColumnLimit); + DoNotMergeNoColumnLimit); + verifyNoChange("A()\n" + " : b(0) {\n" + "}", + DoNotMergeNoColumnLimit); verifyFormat("A()\n" " : b(0) {\n" "}",