Index: include/clang/Format/Format.h =================================================================== --- include/clang/Format/Format.h +++ include/clang/Format/Format.h @@ -186,6 +186,18 @@ /// \endcode bool AllowShortCaseLabelsOnASingleLine; + /// \brief if ``true`` empty inline class functions will have an extra space + /// between the two block braces. This is valid only with AfterFunction and + /// SFS_InlineOnly + /// \code + /// true: + /// class T class T + /// { vs. { + /// void f() { } void f() {} + /// }; }; + /// \endcode + bool AddSpaceInEmptyInlineFunction; + /// \brief Different styles for merging short functions containing at most one /// statement. enum ShortFunctionStyle { @@ -1519,6 +1531,7 @@ AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine && AllowShortCaseLabelsOnASingleLine == R.AllowShortCaseLabelsOnASingleLine && + AddSpaceInEmptyInlineFunction == R.AddSpaceInEmptyInlineFunction && AllowShortFunctionsOnASingleLine == R.AllowShortFunctionsOnASingleLine && AllowShortIfStatementsOnASingleLine == Index: lib/Format/Format.cpp =================================================================== --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -287,6 +287,8 @@ Style.AllowShortBlocksOnASingleLine); IO.mapOptional("AllowShortCaseLabelsOnASingleLine", Style.AllowShortCaseLabelsOnASingleLine); + IO.mapOptional("AddSpaceInEmptyInlineFunction", + Style.AddSpaceInEmptyInlineFunction); IO.mapOptional("AllowShortFunctionsOnASingleLine", Style.AllowShortFunctionsOnASingleLine); IO.mapOptional("AllowShortIfStatementsOnASingleLine", @@ -562,6 +564,7 @@ LLVMStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; LLVMStyle.AllowShortBlocksOnASingleLine = false; LLVMStyle.AllowShortCaseLabelsOnASingleLine = false; + LLVMStyle.AddSpaceInEmptyInlineFunction = false; LLVMStyle.AllowShortIfStatementsOnASingleLine = false; LLVMStyle.AllowShortLoopsOnASingleLine = false; LLVMStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_None; @@ -739,6 +742,7 @@ FormatStyle::RTBS_TopLevel; MozillaStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_TopLevel; + MozillaStyle.AddSpaceInEmptyInlineFunction = true; MozillaStyle.AlwaysBreakTemplateDeclarations = true; MozillaStyle.BinPackParameters = false; MozillaStyle.BinPackArguments = false; Index: lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- lib/Format/UnwrappedLineFormatter.cpp +++ lib/Format/UnwrappedLineFormatter.cpp @@ -327,16 +327,24 @@ Limit -= 2; unsigned MergedLines = 0; + bool EmptyFunc = I[1]->First == I[1]->Last && I + 2 != E && + I[2]->First->is(tok::r_brace); if (MergeShortFunctions || (Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty && - I[1]->First == I[1]->Last && I + 2 != E && - I[2]->First->is(tok::r_brace))) { + EmptyFunc)) { MergedLines = tryMergeSimpleBlock(I + 1, E, Limit); // If we managed to merge the block, count the function header, which is // on a separate line. if (MergedLines > 0) ++MergedLines; } + + if (Style.AddSpaceInEmptyInlineFunction && EmptyFunc && + Style.AllowShortFunctionsOnASingleLine & + FormatStyle::SFS_InlineOnly && + TheLine->Level != 0) { + I[2]->First->SpacesRequiredBefore = 1; + } return MergedLines; } if (TheLine->First->is(tok::kw_if)) { Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -1117,6 +1117,16 @@ " int i = 0;\n" "}"); } + +TEST_F(FormatTest, SpaceInEmptyInlineFunction) { + FormatStyle Style = getMozillaStyle(); + Style.AddSpaceInEmptyInlineFunction = true; + verifyFormat("class T\n" + "{\n" + " void f() { }\n" + "};", + Style); +} //===----------------------------------------------------------------------===// // Tests for classes, namespaces, etc. @@ -9938,6 +9948,7 @@ CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine); CHECK_PARSE_BOOL(AllowShortBlocksOnASingleLine); CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine); + CHECK_PARSE_BOOL(AddSpaceInEmptyInlineFunction); CHECK_PARSE_BOOL(AllowShortIfStatementsOnASingleLine); CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine); CHECK_PARSE_BOOL(AlwaysBreakTemplateDeclarations);