r236091 - clang-format: Fix selective indentaiton in nested blocks.
Daniel Jasper
djasper at google.com
Wed Apr 29 01:29:26 PDT 2015
Author: djasper
Date: Wed Apr 29 03:29:26 2015
New Revision: 236091
URL: http://llvm.org/viewvc/llvm-project?rev=236091&view=rev
Log:
clang-format: Fix selective indentaiton in nested blocks.
Buggy case:
someFunction(
[] {
// comment
int i; // invoke formatting here.
}, // force line break
aaa);
Modified:
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp?rev=236091&r1=236090&r2=236091&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp Wed Apr 29 03:29:26 2015
@@ -461,7 +461,9 @@ UnwrappedLineFormatter::format(const Sma
if (static_cast<int>(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);
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=236091&r1=236090&r2=236091&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Apr 29 03:29:26 2015
@@ -3262,6 +3262,19 @@ TEST_F(FormatTest, IndividualStatementsO
" 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) {
More information about the cfe-commits
mailing list