summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/UnwrappedLineFormatter.cpp4
-rw-r--r--clang/unittests/Format/FormatTest.cpp13
2 files changed, 16 insertions, 1 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index f5120b9f2f3..dd65230cc40 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -461,7 +461,9 @@ UnwrappedLineFormatter::format(const SmallVectorImpl<AnnotatedLine *> &Lines,
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);
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index b23778aaba8..46266adcac7 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/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) {
OpenPOWER on IntegriCloud