forked from OSchip/llvm-project
clang-format: Fix bad indentation of nested blocks.
Before: DEBUG( // { f(); }); After: DEBUG( // { f(); }); Also add additional test to selected formatting of individual statements in nested blocks. llvm-svn: 195952
This commit is contained in:
parent
1df3205e8c
commit
e40caf9ad2
|
@ -340,7 +340,8 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
|
||||||
Penalty += Style.PenaltyBreakFirstLessLess;
|
Penalty += Style.PenaltyBreakFirstLessLess;
|
||||||
|
|
||||||
if (Current.is(tok::l_brace) && Current.BlockKind == BK_Block) {
|
if (Current.is(tok::l_brace) && Current.BlockKind == BK_Block) {
|
||||||
State.Column = State.FirstIndent;
|
State.Column =
|
||||||
|
State.ParenLevel == 0 ? State.FirstIndent : State.Stack.back().Indent;
|
||||||
} else if (Current.isOneOf(tok::r_brace, tok::r_square)) {
|
} else if (Current.isOneOf(tok::r_brace, tok::r_square)) {
|
||||||
if (Current.closesBlockTypeList(Style) ||
|
if (Current.closesBlockTypeList(Style) ||
|
||||||
(Current.MatchingParen &&
|
(Current.MatchingParen &&
|
||||||
|
|
|
@ -2465,6 +2465,14 @@ TEST_F(FormatTest, LayoutNestedBlocks) {
|
||||||
" somethingelse();\n"
|
" somethingelse();\n"
|
||||||
"});",
|
"});",
|
||||||
getLLVMStyleWithColumns(40));
|
getLLVMStyleWithColumns(40));
|
||||||
|
verifyFormat("DEBUG( //\n"
|
||||||
|
" { f(); }, a);");
|
||||||
|
verifyFormat("DEBUG( //\n"
|
||||||
|
" {\n"
|
||||||
|
" f(); //\n"
|
||||||
|
" },\n"
|
||||||
|
" a);");
|
||||||
|
|
||||||
EXPECT_EQ("call(parameter, {\n"
|
EXPECT_EQ("call(parameter, {\n"
|
||||||
" something();\n"
|
" something();\n"
|
||||||
" // Comment too\n"
|
" // Comment too\n"
|
||||||
|
@ -2532,6 +2540,15 @@ TEST_F(FormatTest, IndividualStatementsOfNestedBlocks) {
|
||||||
" int j;\n"
|
" int j;\n"
|
||||||
"} ) ;",
|
"} ) ;",
|
||||||
41, 1, getLLVMStyle()));
|
41, 1, getLLVMStyle()));
|
||||||
|
EXPECT_EQ("DEBUG( {\n"
|
||||||
|
" int i;\n"
|
||||||
|
" int j;\n"
|
||||||
|
"} ) ;",
|
||||||
|
format("DEBUG( {\n"
|
||||||
|
" int i;\n"
|
||||||
|
" int j;\n"
|
||||||
|
"} ) ;",
|
||||||
|
41, 1, getLLVMStyle()));
|
||||||
EXPECT_EQ("DEBUG({\n"
|
EXPECT_EQ("DEBUG({\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
" int j;\n"
|
" int j;\n"
|
||||||
|
|
Loading…
Reference in New Issue