diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -1999,6 +1999,15 @@ Base2 {}; + * ``BILS_AfterComma`` (in configuration: ``AfterComma``) + Break inheritance list only after and commas. + + .. code-block:: c++ + + class Foo : Base1, + Base2 + {}; + **BreakStringLiterals** (``bool``) diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -1829,7 +1829,14 @@ /// Base2 /// {}; /// \endcode - BILS_AfterColon + BILS_AfterColon, + /// Break inheritance list only after the commas. + /// \code + /// class Foo : Base1, + /// Base2 + /// {}; + /// \endcode + BILS_AfterComma }; /// The inheritance list style to use. diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -240,6 +240,7 @@ IO.enumCase(Value, "BeforeColon", FormatStyle::BILS_BeforeColon); IO.enumCase(Value, "BeforeComma", FormatStyle::BILS_BeforeComma); IO.enumCase(Value, "AfterColon", FormatStyle::BILS_AfterColon); + IO.enumCase(Value, "AfterComma", FormatStyle::BILS_AfterComma); } }; diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3639,6 +3639,9 @@ if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma && Right.is(TT_InheritanceComma)) return true; + if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma && + Left.is(TT_InheritanceComma)) + return true; if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\"")) // Multiline raw string literals are special wrt. line breaks. The author // has made a deliberate choice and might have aligned the contents of the @@ -4058,12 +4061,18 @@ if (Right.is(TT_CtorInitializerComma) && Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma) return true; - if (Left.is(TT_InheritanceComma) && - Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma) - return false; - if (Right.is(TT_InheritanceComma) && - Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma) - return true; + if (Left.is(TT_InheritanceComma)) { + if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma) + return false; + else if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma) + return true; + } + if (Right.is(TT_InheritanceComma)) { + if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma) + return true; + else if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma) + return false; + } if ((Left.is(tok::greater) && Right.is(tok::greater)) || (Left.is(tok::less) && Right.is(tok::less))) return false;