Index: clang/include/clang/Format/Format.h =================================================================== --- clang/include/clang/Format/Format.h +++ clang/include/clang/Format/Format.h @@ -1160,6 +1160,23 @@ /// \endcode BraceWrappingFlags BraceWrapping; + /// If ``true``, struct left brace will be placed after line breaks. + /// \code + /// true: + /// struct new_struct struct_name = + /// { + /// a = 1, + /// b = 2, + /// }; + /// + /// false: + /// struct new_struct struct_name = { + /// a = 1, + /// b = 2, + /// }; + /// \endcode + bool BreakBeforeStructInitialization; + /// If ``true``, ternary operators will be placed after line breaks. /// \code /// true: @@ -2431,6 +2448,7 @@ BinPackParameters == R.BinPackParameters && BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators && BreakBeforeBraces == R.BreakBeforeBraces && + BreakBeforeStructInitialization == R.BreakBeforeStructInitialization && BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators && BreakConstructorInitializers == R.BreakConstructorInitializers && CompactNamespaces == R.CompactNamespaces && Index: clang/lib/Format/ContinuationIndenter.cpp =================================================================== --- clang/lib/Format/ContinuationIndenter.cpp +++ clang/lib/Format/ContinuationIndenter.cpp @@ -953,6 +953,8 @@ const FormatToken &Previous = *Current.Previous; // If we are continuing an expression, we want to use the continuation indent. + if (Style.BreakBeforeStructInitialization) + Style.ContinuationIndentWidth = 0; unsigned ContinuationIndent = std::max(State.Stack.back().LastSpace, State.Stack.back().Indent) + Style.ContinuationIndentWidth; Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -513,6 +513,9 @@ Style.BreakInheritanceList == FormatStyle::BILS_BeforeColon) Style.BreakInheritanceList = FormatStyle::BILS_BeforeComma; + IO.mapOptional("BreakBeforeStructInitialization", + Style.BreakBeforeStructInitialization); + IO.mapOptional("BreakBeforeTernaryOperators", Style.BreakBeforeTernaryOperators); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3489,6 +3489,9 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, const FormatToken &Right) { const FormatToken &Left = *Right.Previous; + if (Style.BreakBeforeStructInitialization && Right.is(tok::l_brace) && + (Right.is(BK_BracedInit) || Left.is(tok::equal))) + return true; if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0) return true;