From: Daniel Jasper Date: Wed, 29 Apr 2015 08:29:26 +0000 (+0000) Subject: clang-format: Fix selective indentaiton in nested blocks. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ad0dad7da07944ce6b2a3e719ca87784ccd41af4;p=clang clang-format: Fix selective indentaiton in nested blocks. Buggy case: someFunction( [] { // comment int i; // invoke formatting here. }, // force line break aaa); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236091 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineFormatter.cpp b/lib/Format/UnwrappedLineFormatter.cpp index f5120b9f2f..dd65230cc4 100644 --- a/lib/Format/UnwrappedLineFormatter.cpp +++ b/lib/Format/UnwrappedLineFormatter.cpp @@ -461,7 +461,9 @@ UnwrappedLineFormatter::format(const SmallVectorImpl &Lines, if (static_cast(LevelIndent) - Offset >= 0) LevelIndent -= Offset; - if (Tok->isNot(tok::comment) && !TheLine.InPPDirective) + if ((Tok->isNot(tok::comment) || + IndentForLevel[TheLine.Level] == -1) && + !TheLine.InPPDirective) IndentForLevel[TheLine.Level] = LevelIndent; } else if (!DryRun) { Whitespaces->addUntouchableToken(*Tok, TheLine.InPPDirective); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index b23778aaba..46266adcac 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3262,6 +3262,19 @@ TEST_F(FormatTest, IndividualStatementsOfNestedBlocks) { " int a; //\n" "});", 0, 0, getLLVMStyle())); + EXPECT_EQ("someFunction(\n" + " [] {\n" + " // Only with this comment.\n" + " int i; // invoke formatting here.\n" + " }, // force line break\n" + " aaa);", + format("someFunction(\n" + " [] {\n" + " // Only with this comment.\n" + " int i; // invoke formatting here.\n" + " }, // force line break\n" + " aaa);", + 63, 1, getLLVMStyle())); } TEST_F(FormatTest, PutEmptyBlocksIntoOneLine) {