diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index 3f8a5f49313b2..43896f23afb1f 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -1905,15 +1905,21 @@ the configuration (without a prefix: ``Auto``). Dependent on the value, ``int f() { return 0; }`` can be put on a single line. - Possible values: + Nested configuration flags: + + Different styles for merging short functions containing at most one + statement. - * ``SFS_None`` (in configuration: ``None``) + They can be read as a whole for compatibility. The choices are: + + * ``None`` Never merge functions into a single line. - * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``) + * ``InlineOnly`` Only merge functions defined inside a class. Same as ``inline``, except it does not implies ``empty``: i.e. top level empty functions - are not merged either. + are not merged either. This option is **deprecated** and is retained + for backwards compatibility. See ``Inline`` of ``ShortFunctionStyle``. .. code-block:: c++ @@ -1926,8 +1932,10 @@ the configuration (without a prefix: ``Auto``). void f() { } - * ``SFS_Empty`` (in configuration: ``Empty``) - Only merge empty functions. + * ``Empty`` + Only merge empty functions. This option is **deprecated** and is + retained for backwards compatibility. See ``Empty`` of + ``ShortFunctionStyle``. .. code-block:: c++ @@ -1936,8 +1944,10 @@ the configuration (without a prefix: ``Auto``). bar2(); } - * ``SFS_Inline`` (in configuration: ``Inline``) - Only merge functions defined inside a class. Implies ``empty``. + * ``Inline`` + Only merge functions defined inside a class. Implies ``empty``. This + option is **deprecated** and is retained for backwards compatibility. + See ``Inline`` and ``Empty`` of ``ShortFunctionStyle``. .. code-block:: c++ @@ -1949,7 +1959,7 @@ the configuration (without a prefix: ``Auto``). } void f() {} - * ``SFS_All`` (in configuration: ``All``) + * ``All`` Merge all functions fitting on a single line. .. code-block:: c++ @@ -1959,6 +1969,52 @@ the configuration (without a prefix: ``Auto``). }; void f() { bar(); } + Also can be specified as a nested configuration flag: + + .. code-block:: c++ + + # Example of usage: + AllowShortFunctionsOnASingleLine: InlineOnly + + # or more granular control: + AllowShortFunctionsOnASingleLine: + Empty: false + Inline: true + Other: false + + * ``bool Empty`` Merge top-level empty functions. + + .. code-block:: c++ + + void f() {} + void f2() { + bar2(); + } + void f3() { /* comment */ } + + * ``bool Inline`` Merge functions defined inside a class. + + .. code-block:: c++ + + class Foo { + void f() { foo(); } + void g() {} + }; + void f() { + foo(); + } + void f() { + } + + * ``bool Other`` Merge all functions fitting on a single line. Please note that this + control does not include Empty + + .. code-block:: c++ + + class Foo { + void f() { foo(); } + }; + void f() { bar(); } .. _AllowShortIfStatementsOnASingleLine: diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index f6ceef08b46da..7ee954606718b 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -827,50 +827,114 @@ struct FormatStyle { /// Different styles for merging short functions containing at most one /// statement. - enum ShortFunctionStyle : int8_t { - /// Never merge functions into a single line. - SFS_None, - /// Only merge functions defined inside a class. Same as ``inline``, - /// except it does not implies ``empty``: i.e. top level empty functions - /// are not merged either. - /// \code - /// class Foo { - /// void f() { foo(); } - /// }; - /// void f() { - /// foo(); - /// } - /// void f() { - /// } - /// \endcode - SFS_InlineOnly, - /// Only merge empty functions. + /// + /// They can be read as a whole for compatibility. The choices are: + /// + /// * ``None`` + /// Never merge functions into a single line. + /// + /// * ``InlineOnly`` + /// Only merge functions defined inside a class. Same as ``inline``, + /// except it does not implies ``empty``: i.e. top level empty functions + /// are not merged either. This option is **deprecated** and is retained + /// for backwards compatibility. See ``Inline`` of ``ShortFunctionStyle``. + /// \code + /// class Foo { + /// void f() { foo(); } + /// }; + /// void f() { + /// foo(); + /// } + /// void f() { + /// } + /// \endcode + /// + /// * ``Empty`` + /// Only merge empty functions. This option is **deprecated** and is + /// retained for backwards compatibility. See ``Empty`` of + /// ``ShortFunctionStyle``. + /// \code + /// void f() {} + /// void f2() { + /// bar2(); + /// } + /// \endcode + /// + /// * ``Inline`` + /// Only merge functions defined inside a class. Implies ``empty``. This + /// option is **deprecated** and is retained for backwards compatibility. + /// See ``Inline`` and ``Empty`` of ``ShortFunctionStyle``. + /// \code + /// class Foo { + /// void f() { foo(); } + /// }; + /// void f() { + /// foo(); + /// } + /// void f() {} + /// \endcode + /// + /// * ``All`` + /// Merge all functions fitting on a single line. + /// \code + /// class Foo { + /// void f() { foo(); } + /// }; + /// void f() { bar(); } + /// \endcode + /// + /// Also can be specified as a nested configuration flag: + /// \code + /// # Example of usage: + /// AllowShortFunctionsOnASingleLine: InlineOnly + /// + /// # or more granular control: + /// AllowShortFunctionsOnASingleLine: + /// Empty: false + /// Inline: true + /// Other: false + /// \endcode + struct ShortFunctionStyle { + /// Merge top-level empty functions. /// \code /// void f() {} /// void f2() { /// bar2(); /// } + /// void f3() { /* comment */ } /// \endcode - SFS_Empty, - /// Only merge functions defined inside a class. Implies ``empty``. + bool Empty; + /// Merge functions defined inside a class. /// \code /// class Foo { /// void f() { foo(); } + /// void g() {} /// }; /// void f() { /// foo(); /// } - /// void f() {} + /// void f() { + /// } /// \endcode - SFS_Inline, - /// Merge all functions fitting on a single line. + bool Inline; + /// Merge all functions fitting on a single line. Please note that this + /// control does not include Empty /// \code /// class Foo { /// void f() { foo(); } /// }; /// void f() { bar(); } /// \endcode - SFS_All, + bool Other; + + bool operator==(const ShortFunctionStyle &R) const { + return Empty == R.Empty && Inline == R.Inline && Other == R.Other; + } + bool operator!=(const ShortFunctionStyle &R) const { return !(*this == R); } + ShortFunctionStyle() : Empty(false), Inline(false), Other(false) {} + ShortFunctionStyle(bool Empty, bool Inline, bool Other) + : Empty(Empty), Inline(Inline), Other(Other) {} + bool isAll() const { return Empty && Inline && Other; } }; /// Dependent on the value, ``int f() { return 0; }`` can be put on a diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index c601967a8715c..859b19fe7d3e4 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -622,15 +622,38 @@ template <> struct ScalarEnumerationTraits { } }; -template <> struct ScalarEnumerationTraits { - static void enumeration(IO &IO, FormatStyle::ShortFunctionStyle &Value) { - IO.enumCase(Value, "None", FormatStyle::SFS_None); - IO.enumCase(Value, "false", FormatStyle::SFS_None); - IO.enumCase(Value, "All", FormatStyle::SFS_All); - IO.enumCase(Value, "true", FormatStyle::SFS_All); - IO.enumCase(Value, "Inline", FormatStyle::SFS_Inline); - IO.enumCase(Value, "InlineOnly", FormatStyle::SFS_InlineOnly); - IO.enumCase(Value, "Empty", FormatStyle::SFS_Empty); +template <> struct MappingTraits { + static void enumInput(IO &IO, FormatStyle::ShortFunctionStyle &Value) { + IO.enumCase(Value, "None", FormatStyle::ShortFunctionStyle({})); + IO.enumCase(Value, "Empty", + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/false, + /*Other=*/false})); + IO.enumCase(Value, "Inline", + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/false})); + IO.enumCase(Value, "InlineOnly", + FormatStyle::ShortFunctionStyle({/*Empty=*/false, + /*Inline=*/true, + /*Other=*/false})); + IO.enumCase(Value, "All", + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/true})); + + // For backward compatibility. + IO.enumCase(Value, "true", + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/true})); + IO.enumCase(Value, "false", FormatStyle::ShortFunctionStyle({})); + } + + static void mapping(IO &IO, FormatStyle::ShortFunctionStyle &Value) { + IO.mapOptional("Empty", Value.Empty); + IO.mapOptional("Inline", Value.Inline); + IO.mapOptional("Other", Value.Other); } }; @@ -1510,7 +1533,10 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { LLVMStyle.AllowShortCaseLabelsOnASingleLine = false; LLVMStyle.AllowShortCompoundRequirementOnASingleLine = true; LLVMStyle.AllowShortEnumsOnASingleLine = true; - LLVMStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; + LLVMStyle.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/true}); LLVMStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never; LLVMStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All; LLVMStyle.AllowShortLoopsOnASingleLine = false; @@ -1798,7 +1824,10 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { GoogleStyle.AlignOperands = FormatStyle::OAS_DontAlign; GoogleStyle.AlignTrailingComments = {}; GoogleStyle.AlignTrailingComments.Kind = FormatStyle::TCAS_Never; - GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; + GoogleStyle.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/false, + /*Other=*/false}); GoogleStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never; GoogleStyle.AlwaysBreakBeforeMultilineStrings = false; GoogleStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment; @@ -1808,7 +1837,10 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { } else if (Language == FormatStyle::LK_JavaScript) { GoogleStyle.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak; GoogleStyle.AlignOperands = FormatStyle::OAS_DontAlign; - GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; + GoogleStyle.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/false, + /*Other=*/false}); // TODO: still under discussion whether to switch to SLS_All. GoogleStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_Empty; GoogleStyle.AlwaysBreakBeforeMultilineStrings = false; @@ -1825,7 +1857,10 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { GoogleStyle.NamespaceIndentation = FormatStyle::NI_All; GoogleStyle.SpacesInContainerLiterals = false; } else if (Language == FormatStyle::LK_Proto) { - GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; + GoogleStyle.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/false, + /*Other=*/false}); GoogleStyle.AlwaysBreakBeforeMultilineStrings = false; // This affects protocol buffer options specifications and text protos. // Text protos are currently mostly formatted inside C++ raw string literals @@ -1844,7 +1879,10 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { GoogleStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve; } else if (Language == FormatStyle::LK_CSharp) { - GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; + GoogleStyle.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/false, + /*Other=*/false}); GoogleStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never; GoogleStyle.BreakStringLiterals = false; GoogleStyle.ColumnLimit = 100; @@ -1903,7 +1941,10 @@ FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language) { ChromiumStyle.AllowShortLoopsOnASingleLine = false; } else { ChromiumStyle.AllowAllParametersOfDeclarationOnNextLine = false; - ChromiumStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; + ChromiumStyle.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/false}); ChromiumStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never; ChromiumStyle.AllowShortLoopsOnASingleLine = false; ChromiumStyle.BinPackParameters = FormatStyle::BPPS_OnePerLine; @@ -1917,7 +1958,10 @@ FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language) { FormatStyle getMozillaStyle() { FormatStyle MozillaStyle = getLLVMStyle(); MozillaStyle.AllowAllParametersOfDeclarationOnNextLine = false; - MozillaStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; + MozillaStyle.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/false}); MozillaStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_TopLevel; MozillaStyle.BinPackArguments = false; @@ -1999,7 +2043,7 @@ FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language) { Style.BraceWrapping.BeforeWhile = false; Style.PenaltyReturnTypeOnItsOwnLine = 1000; Style.AllowShortEnumsOnASingleLine = false; - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + Style.AllowShortFunctionsOnASingleLine = FormatStyle::ShortFunctionStyle({}); Style.AllowShortCaseLabelsOnASingleLine = false; Style.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never; Style.AllowShortLoopsOnASingleLine = false; diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index ef5f07e2c62ee..02b5140e763cf 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -5685,11 +5685,27 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, if (Right.is(tok::r_brace) && Left.is(tok::l_brace) && !Left.Children.empty()) { // Support AllowShortFunctionsOnASingleLine for JavaScript. - return Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_None || - Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Empty || - (Left.NestingLevel == 0 && Line.Level == 0 && - Style.AllowShortFunctionsOnASingleLine & - FormatStyle::SFS_InlineOnly); + const auto &shortFuncConfig = Style.AllowShortFunctionsOnASingleLine; + + // SFS_All + if (shortFuncConfig.isAll()) + return false; + + // SFS_None and SFS_Empty + if (shortFuncConfig == FormatStyle::ShortFunctionStyle{}) + return true; + + // SFS_Empty + if (shortFuncConfig == FormatStyle::ShortFunctionStyle{/*Empty=*/true, + /*Inline=*/false, + /*Other=*/false}) { + return true; + } + + if (Left.NestingLevel == 0 && Line.Level == 0) + return shortFuncConfig.Inline && !shortFuncConfig.Other; + + return shortFuncConfig.Other; } } else if (Style.isJava()) { if (Right.is(tok::plus) && Left.is(tok::string_literal) && AfterRight && diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 617d46ad281d5..5866d33572116 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -291,54 +291,59 @@ class LineJoiner { auto ShouldMergeShortFunctions = [this, &I, &NextLine, PreviousLine, TheLine]() { - if (Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_All) + if (Style.AllowShortFunctionsOnASingleLine.isAll()) return true; - if (Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty && - NextLine.First->is(tok::r_brace)) { + + // there might be a case where empty function is in class, so need to + // check inline later + bool empty_function = NextLine.First->is(tok::r_brace); + if (Style.AllowShortFunctionsOnASingleLine.Empty && empty_function) return true; - } - if (Style.AllowShortFunctionsOnASingleLine & - FormatStyle::SFS_InlineOnly) { + if (TheLine->Level != 0) { + if (!Style.AllowShortFunctionsOnASingleLine.Inline) + return false; + // Just checking TheLine->Level != 0 is not enough, because it // provokes treating functions inside indented namespaces as short. if (Style.isJavaScript() && TheLine->Last->is(TT_FunctionLBrace)) return true; - if (TheLine->Level != 0) { - if (!PreviousLine) - return false; - - // TODO: Use IndentTracker to avoid loop? - // Find the last line with lower level. - const AnnotatedLine *Line = nullptr; - for (auto J = I - 1; J >= AnnotatedLines.begin(); --J) { - assert(*J); - if ((*J)->InPPDirective || (*J)->isComment() || - (*J)->Level > TheLine->Level) { - continue; - } - if ((*J)->Level < TheLine->Level || - (Style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths && - (*J)->First->is(tok::l_brace))) { - Line = *J; - break; - } + if (!PreviousLine) + return false; + + // TODO: Use IndentTracker to avoid loop? + // Find the last line with lower level. + const AnnotatedLine *Line = nullptr; + for (auto J = I - 1; J >= AnnotatedLines.begin(); --J) { + assert(*J); + if ((*J)->InPPDirective || (*J)->isComment() || + (*J)->Level > TheLine->Level) { + continue; } + if ((*J)->Level < TheLine->Level || + (Style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths && + (*J)->First->is(tok::l_brace))) { + Line = *J; + break; + } + } - if (!Line) - return false; + if (!Line) + return false; - // Check if the found line starts a record. - const auto *LastNonComment = Line->getLastNonComment(); - // There must be another token (usually `{`), because we chose a - // non-PPDirective and non-comment line that has a smaller level. - assert(LastNonComment); - return isRecordLBrace(*LastNonComment); - } + // Check if the found line starts a record. + const auto *LastNonComment = Line->getLastNonComment(); + // There must be another token (usually `{`), because we chose a + // non-PPDirective and non-comment line that has a smaller level. + assert(LastNonComment); + return isRecordLBrace(*LastNonComment); } - return false; + if (empty_function && !Style.AllowShortFunctionsOnASingleLine.Empty) + return false; + + return Style.AllowShortFunctionsOnASingleLine.Other; }; bool MergeShortFunctions = ShouldMergeShortFunctions(); @@ -551,7 +556,7 @@ class LineJoiner { unsigned MergedLines = 0; if (MergeShortFunctions || - (Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty && + (Style.AllowShortFunctionsOnASingleLine.Empty && NextLine.First == NextLine.Last && I + 2 != E && I[2]->First->is(tok::r_brace))) { MergedLines = tryMergeSimpleBlock(I + 1, E, Limit); diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp index 2b08b794792e9..6612c3672837d 100644 --- a/clang/unittests/Format/ConfigParseTest.cpp +++ b/clang/unittests/Format/ConfigParseTest.cpp @@ -619,20 +619,39 @@ TEST(ConfigParseTest, ParsesConfiguration) { CHECK_PARSE("AllowShortBlocksOnASingleLine: true", AllowShortBlocksOnASingleLine, FormatStyle::SBS_Always); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; CHECK_PARSE("AllowShortFunctionsOnASingleLine: None", - AllowShortFunctionsOnASingleLine, FormatStyle::SFS_None); + AllowShortFunctionsOnASingleLine, + FormatStyle::ShortFunctionStyle({})); CHECK_PARSE("AllowShortFunctionsOnASingleLine: Inline", - AllowShortFunctionsOnASingleLine, FormatStyle::SFS_Inline); + AllowShortFunctionsOnASingleLine, + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/false})); CHECK_PARSE("AllowShortFunctionsOnASingleLine: Empty", - AllowShortFunctionsOnASingleLine, FormatStyle::SFS_Empty); + AllowShortFunctionsOnASingleLine, + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/false, + /*Other=*/false})); CHECK_PARSE("AllowShortFunctionsOnASingleLine: All", - AllowShortFunctionsOnASingleLine, FormatStyle::SFS_All); + AllowShortFunctionsOnASingleLine, + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/true})); + CHECK_PARSE("AllowShortFunctionsOnASingleLine: InlineOnly", + AllowShortFunctionsOnASingleLine, + FormatStyle::ShortFunctionStyle({/*Empty=*/false, + /*Inline=*/true, + /*Other=*/false})); + // For backward compatibility: CHECK_PARSE("AllowShortFunctionsOnASingleLine: false", - AllowShortFunctionsOnASingleLine, FormatStyle::SFS_None); + AllowShortFunctionsOnASingleLine, + FormatStyle::ShortFunctionStyle({})); CHECK_PARSE("AllowShortFunctionsOnASingleLine: true", - AllowShortFunctionsOnASingleLine, FormatStyle::SFS_All); + AllowShortFunctionsOnASingleLine, + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/true})); Style.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All; CHECK_PARSE("AllowShortLambdasOnASingleLine: None", diff --git a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp index b26b9f4f4ff62..d3d0a0b56b5a0 100644 --- a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp +++ b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp @@ -540,7 +540,7 @@ TEST_F(DefinitionBlockSeparatorTest, Leave) { TEST_F(DefinitionBlockSeparatorTest, CSharp) { FormatStyle Style = getLLVMStyle(FormatStyle::LK_CSharp); Style.SeparateDefinitionBlocks = FormatStyle::SDS_Always; - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + Style.AllowShortFunctionsOnASingleLine = FormatStyle::ShortFunctionStyle({}); Style.AllowShortEnumsOnASingleLine = false; verifyFormat("namespace {\r\n" "public class SomeTinyClass {\r\n" @@ -581,7 +581,7 @@ TEST_F(DefinitionBlockSeparatorTest, CSharp) { TEST_F(DefinitionBlockSeparatorTest, JavaScript) { FormatStyle Style = getLLVMStyle(FormatStyle::LK_JavaScript); Style.SeparateDefinitionBlocks = FormatStyle::SDS_Always; - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + Style.AllowShortFunctionsOnASingleLine = FormatStyle::ShortFunctionStyle({}); Style.AllowShortEnumsOnASingleLine = false; verifyFormat("export const enum Foo {\n" " A = 1,\n" diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index b62d49e17c83f..c84c0510cce0f 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -388,7 +388,10 @@ TEST_F(FormatTest, RemovesEmptyLines) { "} // namespace"); FormatStyle Style = getLLVMStyle(); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; + Style.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/true}); Style.MaxEmptyLinesToKeep = 2; Style.BreakBeforeBraces = FormatStyle::BS_Custom; Style.BraceWrapping.AfterClass = true; @@ -3377,13 +3380,16 @@ TEST_F(FormatTest, MultiLineControlStatements) { Style.BraceWrapping.AfterFunction = true; Style.BraceWrapping.AfterStruct = false; Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_MultiLine; - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; + Style.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/true}); Style.ColumnLimit = 80; verifyFormat("void shortfunction() { bar(); }", Style); verifyFormat("struct T shortfunction() { return bar(); }", Style); verifyFormat("struct T {};", Style); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + Style.AllowShortFunctionsOnASingleLine = FormatStyle::ShortFunctionStyle({}); verifyFormat("void shortfunction()\n" "{\n" " bar();\n" @@ -3398,7 +3404,10 @@ TEST_F(FormatTest, MultiLineControlStatements) { Style.BraceWrapping.AfterFunction = false; Style.BraceWrapping.AfterStruct = true; - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; + Style.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/true}); verifyFormat("void shortfunction() { bar(); }", Style); verifyFormat("struct T shortfunction() { return bar(); }", Style); verifyFormat("struct T\n" @@ -3406,7 +3415,7 @@ TEST_F(FormatTest, MultiLineControlStatements) { "};", Style); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + Style.AllowShortFunctionsOnASingleLine = FormatStyle::ShortFunctionStyle({}); verifyFormat("void shortfunction() {\n" " bar();\n" "}", @@ -4201,7 +4210,9 @@ TEST_F(FormatTest, FormatsNamespaces) { FormatStyle ShortInlineFunctions = getLLVMStyle(); ShortInlineFunctions.NamespaceIndentation = FormatStyle::NI_All; ShortInlineFunctions.AllowShortFunctionsOnASingleLine = - FormatStyle::SFS_Inline; + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/false}); verifyFormat("namespace {\n" " void f() {\n" " return;\n" @@ -8326,7 +8337,7 @@ TEST_F(FormatTest, BreakConstructorInitializersAfterColon) { "};", Style); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + Style.AllowShortFunctionsOnASingleLine = FormatStyle::ShortFunctionStyle({}); verifyNoChange("SomeClass::Constructor() :\n" " a(a), b(b), c(c) {\n" "}", @@ -8337,7 +8348,10 @@ TEST_F(FormatTest, BreakConstructorInitializersAfterColon) { Style); Style.ColumnLimit = 80; - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; + Style.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/true}); Style.ConstructorInitializerIndentWidth = 2; verifyFormat("SomeClass::Constructor() : a(a), b(b), c(c) {}", Style); verifyFormat("SomeClass::Constructor() :\n" @@ -12671,7 +12685,8 @@ TEST_F(FormatTest, UnderstandsAttributes) { verifyFormat("__attr1(nodebug) ::qualified_type f();", CustomAttrs); // Check that these are not parsed as function declarations: - CustomAttrs.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + CustomAttrs.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({}); CustomAttrs.BreakBeforeBraces = FormatStyle::BS_Allman; verifyFormat("SomeType s(InitValue);", CustomAttrs); verifyFormat("SomeType s{InitValue};", CustomAttrs); @@ -12772,7 +12787,8 @@ TEST_F(FormatTest, UnderstandsSquareAttributes) { // Make sure we do not parse attributes as lambda introducers. FormatStyle MultiLineFunctions = getLLVMStyle(); - MultiLineFunctions.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + MultiLineFunctions.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({}); verifyFormat("[[unused]] int b() {\n" " return 42;\n" "}", @@ -14870,7 +14886,8 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) { TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) { FormatStyle DoNotMerge = getLLVMStyle(); - DoNotMerge.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + DoNotMerge.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({}); verifyFormat("void f() { return 42; }"); verifyFormat("void f() {\n" @@ -14941,7 +14958,7 @@ TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) { FormatStyle DoNotMergeNoColumnLimit = NoColumnLimit; DoNotMergeNoColumnLimit.AllowShortFunctionsOnASingleLine = - FormatStyle::SFS_None; + FormatStyle::ShortFunctionStyle({}); verifyFormat("A() : b(0) {\n" "}", DoNotMergeNoColumnLimit); @@ -14989,7 +15006,10 @@ TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) { TEST_F(FormatTest, PullEmptyFunctionDefinitionsIntoSingleLine) { FormatStyle MergeEmptyOnly = getLLVMStyle(); - MergeEmptyOnly.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; + MergeEmptyOnly.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/false, + /*Other=*/false}); verifyFormat("class C {\n" " int f() {}\n" "};", @@ -15018,7 +15038,10 @@ TEST_F(FormatTest, PullEmptyFunctionDefinitionsIntoSingleLine) { TEST_F(FormatTest, PullInlineFunctionDefinitionsIntoSingleLine) { FormatStyle MergeInlineOnly = getLLVMStyle(); - MergeInlineOnly.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; + MergeInlineOnly.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/false}); verifyFormat("class C {\n" " int f() { return 42; }\n" "};", @@ -15120,10 +15143,146 @@ TEST_F(FormatTest, PullInlineFunctionDefinitionsIntoSingleLine) { MergeInlineOnly); } +TEST_F(FormatTest, CustomShortFunctionOptions) { + FormatStyle CustomEmpty = getLLVMStyle(); + CustomEmpty.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/false, + /*Other=*/false}); + + // Empty functions should be on a single line + verifyFormat("int f() {}", CustomEmpty); + verifyFormat("class C {\n" + " int f() {}\n" + "};", + CustomEmpty); + + // Non-empty functions should be multi-line + verifyFormat("int f() {\n" + " return 42;\n" + "}", + CustomEmpty); + verifyFormat("class C {\n" + " int f() {\n" + " return 42;\n" + " }\n" + "};", + CustomEmpty); + + // test with comment + verifyFormat("void f3() { /* comment */ }", CustomEmpty); + + // Test with AfterFunction = true + CustomEmpty.BreakBeforeBraces = FormatStyle::BS_Custom; + CustomEmpty.BraceWrapping.AfterFunction = true; + verifyFormat("int f() {}", CustomEmpty); + verifyFormat("int g()\n" + "{\n" + " return 42;\n" + "}", + CustomEmpty); + + // Test with Inline = true, All = false + FormatStyle CustomInline = getLLVMStyle(); + CustomInline.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/false, + /*Inline=*/true, + /*Other=*/false}); + + verifyFormat("class C {\n" + " int f() {}\n" + "};", + CustomInline); + + // Non-empty inline functions should be single-line + verifyFormat("class C {\n" + " int f() { return 42; }\n" + "};", + CustomInline); + + // Non-inline functions should be multi-line + verifyFormat("int f() {\n" + " return 42;\n" + "}", + CustomInline); + verifyFormat("int g() {\n" + "}", + CustomInline); + + // Test with All = true + FormatStyle CustomAll = getLLVMStyle(); + CustomAll.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/true}); + + // All functions should be on a single line if they fit + verifyFormat("int f() { return 42; }", CustomAll); + verifyFormat("int g() { return f() + h(); }", CustomAll); + verifyFormat("class C {\n" + " int f() { return 42; }\n" + "};", + CustomAll); + + verifyFormat("int f() {}", CustomAll); + verifyFormat("class C {\n" + " int f() {}\n" + "};", + CustomAll); + + // Test various combinations + FormatStyle CustomMixed = getLLVMStyle(); + CustomMixed.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/false}); + + // Empty functions should be on a single line + verifyFormat("int f() {}", CustomMixed); + verifyFormat("class C {\n" + " int f() {}\n" + "};", + CustomMixed); + + // Inline non-empty functions should be on a single line + verifyFormat("class C {\n" + " int f() { return 42; }\n" + "};", + CustomMixed); + + // Non-inline non-empty functions should be multi-line + verifyFormat("int f() {\n" + " return 42;\n" + "}", + CustomMixed); + + FormatStyle OnlyOther = getLLVMStyle(); + OnlyOther.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/false, + /*Inline=*/false, + /*Other=*/true}); + verifyFormat("void topLevelEmpty() {\n" + "}", + OnlyOther); + + verifyFormat("void topLevelNonEmpty() { return; }", OnlyOther); + + verifyFormat("class C {\n" + " int inlineEmpty() {\n" + " }\n" + " int inlineNonempty() {\n" + " return 42;\n" + " }\n" + "};", + OnlyOther); +} + TEST_F(FormatTest, PullInlineOnlyFunctionDefinitionsIntoSingleLine) { FormatStyle MergeInlineOnly = getLLVMStyle(); MergeInlineOnly.AllowShortFunctionsOnASingleLine = - FormatStyle::SFS_InlineOnly; + FormatStyle::ShortFunctionStyle({/*Empty=*/false, + /*Inline=*/true, + /*Other=*/false}); verifyFormat("class C {\n" " int f() { return 42; }\n" "};", @@ -15175,7 +15334,7 @@ TEST_F(FormatTest, PullInlineOnlyFunctionDefinitionsIntoSingleLine) { TEST_F(FormatTest, SplitEmptyFunction) { FormatStyle Style = getLLVMStyleWithColumns(40); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + Style.AllowShortFunctionsOnASingleLine = FormatStyle::ShortFunctionStyle({}); Style.BreakBeforeBraces = FormatStyle::BS_Custom; Style.BraceWrapping.AfterFunction = true; Style.BraceWrapping.SplitEmptyFunction = false; @@ -15194,7 +15353,10 @@ TEST_F(FormatTest, SplitEmptyFunction) { "}", Style); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; + Style.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/false, + /*Other=*/false}); verifyFormat("int f() {}", Style); verifyFormat("int aaaaaaaaaaaaaa(int bbbbbbbbbbbbbb)\n" "{}", @@ -15205,7 +15367,10 @@ TEST_F(FormatTest, SplitEmptyFunction) { "}", Style); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; + Style.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/false}); verifyFormat("class Foo {\n" " int f() {}\n" "};", @@ -15227,7 +15392,10 @@ TEST_F(FormatTest, SplitEmptyFunction) { "};", Style); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; + Style.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/true}); verifyFormat("int f() {}", Style); verifyFormat("int f() { return 0; }", Style); verifyFormat("int aaaaaaaaaaaaaa(int bbbbbbbbbbbbbb)\n" @@ -15242,7 +15410,7 @@ TEST_F(FormatTest, SplitEmptyFunction) { TEST_F(FormatTest, SplitEmptyFunctionButNotRecord) { FormatStyle Style = getLLVMStyleWithColumns(40); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + Style.AllowShortFunctionsOnASingleLine = FormatStyle::ShortFunctionStyle({}); Style.BreakBeforeBraces = FormatStyle::BS_Custom; Style.BraceWrapping.AfterFunction = true; Style.BraceWrapping.SplitEmptyFunction = true; @@ -15272,7 +15440,10 @@ TEST_F(FormatTest, SplitEmptyFunctionButNotRecord) { TEST_F(FormatTest, KeepShortFunctionAfterPPElse) { FormatStyle Style = getLLVMStyle(); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; + Style.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/true}); verifyFormat("#ifdef A\n" "int f() {}\n" "#else\n" @@ -21395,7 +21566,9 @@ TEST_F(FormatTest, WhitesmithsBraceBreaking) { // Make a few changes to the style for testing purposes WhitesmithsBraceStyle.AllowShortFunctionsOnASingleLine = - FormatStyle::SFS_Empty; + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/false, + /*Other=*/false}); WhitesmithsBraceStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_None; // FIXME: this test case can't decide whether there should be a blank line @@ -22940,7 +23113,7 @@ TEST_F(FormatTest, BreakConstructorInitializersBeforeComma) { "}", Style); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + Style.AllowShortFunctionsOnASingleLine = FormatStyle::ShortFunctionStyle({}); verifyFormat("SomeClass::Constructor()\n" " : a(a)\n" " , b(b)\n" @@ -22951,7 +23124,10 @@ TEST_F(FormatTest, BreakConstructorInitializersBeforeComma) { Style); Style.ColumnLimit = 80; - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; + Style.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/true}); Style.ConstructorInitializerIndentWidth = 2; verifyFormat("SomeClass::Constructor()\n" " : a(a)\n" @@ -27133,7 +27309,7 @@ TEST_F(FormatTest, FormatDecayCopy) { TEST_F(FormatTest, Cpp20ModulesSupport) { FormatStyle Style = getLLVMStyle(); Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Never; - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + Style.AllowShortFunctionsOnASingleLine = FormatStyle::ShortFunctionStyle({}); verifyFormat("export import foo;", Style); verifyFormat("export import foo:bar;", Style); diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp index 151f7072e0c65..22c757509f5fb 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -1660,7 +1660,10 @@ TEST_F(FormatTestCSharp, EmptyShortBlock) { TEST_F(FormatTestCSharp, ShortFunctions) { FormatStyle Style = getLLVMStyle(FormatStyle::LK_CSharp); Style.NamespaceIndentation = FormatStyle::NI_All; - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; + Style.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/false}); verifyFormat("interface Interface {\n" " void f() { return; }\n" "};", diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 1cfacc060d944..03e55e4498fd4 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -1015,7 +1015,10 @@ TEST_F(FormatTestJS, TrailingCommaInsertion) { TEST_F(FormatTestJS, FunctionLiterals) { FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; + Style.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/false}); verifyFormat("doFoo(function() {});"); verifyFormat("doFoo(function() { return 1; });", Style); verifyFormat("var func = function() {\n" @@ -1128,7 +1131,10 @@ TEST_F(FormatTestJS, DontWrapEmptyLiterals) { TEST_F(FormatTestJS, InliningFunctionLiterals) { FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; + Style.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/false}); verifyFormat("var func = function() {\n" " return 1;\n" "};", @@ -1143,7 +1149,10 @@ TEST_F(FormatTestJS, InliningFunctionLiterals) { "}", Style); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; + Style.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/true}); verifyFormat("var func = function() { return 1; };", Style); verifyFormat("var func = doSomething(function() { return 1; });", Style); verifyFormat( @@ -1154,7 +1163,7 @@ TEST_F(FormatTestJS, InliningFunctionLiterals) { "}", Style); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + Style.AllowShortFunctionsOnASingleLine = FormatStyle::ShortFunctionStyle({}); verifyFormat("var func = function() {\n" " return 1;\n" "};", @@ -1176,16 +1185,53 @@ TEST_F(FormatTestJS, InliningFunctionLiterals) { "}", Style); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; + Style.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/false, + /*Other=*/false}); verifyFormat("var func = function() {\n" " return 1;\n" "};", Style); } +TEST_F(FormatTestJS, InliningFunctionLiteralsNew) { + FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript); + Style.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/false, + /*Inline=*/false, + /*Other=*/true}); + verifyFormat("var func = function() { return 1; };", Style); + verifyFormat("var func = doSomething(function() {\n" + " return 1;\n" + "});", + Style); + verifyFormat("var outer = function() {\n" + " var inner = function() {\n" + " return 1;\n" + " }\n" + "};", + Style); + verifyFormat("function outer1(a, b) {\n" + " function inner1(a, b) {\n" + " return a;\n" + " }\n" + "}", + Style); + + verifyFormat("function outer1(a, b) {\n" + " function inner1_empty(a, b) {\n" + " }\n" + "}", + Style); +} + TEST_F(FormatTestJS, MultipleFunctionLiterals) { FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; + Style.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/true}); verifyFormat("promise.then(\n" " function success() {\n" " doFoo();\n" diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index e01c1d6d7e684..77ca00d0fd132 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -596,7 +596,10 @@ TEST_F(FormatTestJava, RetainsLogicalShifts) { TEST_F(FormatTestJava, ShortFunctions) { FormatStyle Style = getLLVMStyle(FormatStyle::LK_Java); - Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; + Style.AllowShortFunctionsOnASingleLine = + FormatStyle::ShortFunctionStyle({/*Empty=*/true, + /*Inline=*/true, + /*Other=*/false}); verifyFormat("enum Enum {\n" " E1,\n" " E2;\n"