Index: docs/ClangFormatStyleOptions.rst =================================================================== --- docs/ClangFormatStyleOptions.rst +++ docs/ClangFormatStyleOptions.rst @@ -324,6 +324,7 @@ * ``bool AfterUnion`` Wrap union definitions. * ``bool BeforeCatch`` Wrap before ``catch``. * ``bool BeforeElse`` Wrap before ``else``. + * ``bool BeforeWhileInDoWhile`` Wrap before ``while`` in do...while. * ``bool IndentBraces`` Indent the wrapped braces themselves. Index: include/clang/Format/Format.h =================================================================== --- include/clang/Format/Format.h +++ include/clang/Format/Format.h @@ -265,6 +265,8 @@ bool BeforeCatch; /// \brief Wrap before \c else. bool BeforeElse; + /// \brief Wrap before \c while in do...while. + bool BeforeWhileInDoWhile; /// \brief Indent the wrapped braces themselves. bool IndentBraces; }; Index: lib/Format/Format.cpp =================================================================== --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -347,6 +347,7 @@ IO.mapOptional("AfterUnion", Wrapping.AfterUnion); IO.mapOptional("BeforeCatch", Wrapping.BeforeCatch); IO.mapOptional("BeforeElse", Wrapping.BeforeElse); + IO.mapOptional("BeforeWhileInDoWhile", Wrapping.BeforeWhileInDoWhile); IO.mapOptional("IndentBraces", Wrapping.IndentBraces); } }; @@ -418,7 +419,7 @@ return Style; FormatStyle Expanded = Style; Expanded.BraceWrapping = {false, false, false, false, false, false, - false, false, false, false, false}; + false, false, false, false, false, false}; switch (Style.BreakBeforeBraces) { case FormatStyle::BS_Linux: Expanded.BraceWrapping.AfterClass = true; @@ -450,7 +451,7 @@ break; case FormatStyle::BS_GNU: Expanded.BraceWrapping = {true, true, true, true, true, true, - true, true, true, true, true}; + true, true, true, true, true, true}; break; case FormatStyle::BS_WebKit: Expanded.BraceWrapping.AfterFunction = true; @@ -487,7 +488,7 @@ LLVMStyle.BreakBeforeTernaryOperators = true; LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach; LLVMStyle.BraceWrapping = {false, false, false, false, false, false, - false, false, false, false, false}; + false, false, false, false, false, false}; LLVMStyle.BreakConstructorInitializersBeforeComma = false; LLVMStyle.BreakAfterJavaFieldAnnotations = false; LLVMStyle.ColumnLimit = 80; Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -1472,7 +1472,10 @@ parseStructuralElement(); --Line->Level; } - + if (FormatTok->Tok.is(tok::kw_while) && + Style.BraceWrapping.BeforeWhileInDoWhile) { + addUnwrappedLine(); + } // FIXME: Add error handling. if (!FormatTok->Tok.is(tok::kw_while)) { addUnwrappedLine(); Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -6582,7 +6582,7 @@ " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb};"); verifyNoCrash("a<,"); - + // No braced initializer here. verifyFormat("void f() {\n" " struct Dummy {};\n" @@ -9823,6 +9823,7 @@ CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterUnion); CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeCatch); CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeElse); + CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeWhileInDoWhile); CHECK_PARSE_NESTED_BOOL(BraceWrapping, IndentBraces); }