clang-format: Don't format unrelated nested blocks.

With this change:

  SomeFunction(
      [] {
	int i;
	 return i;  // Format this line.
      },
      [] {
	 return 2;  // Don't "fix" this.
      });

llvm-svn: 262216
This commit is contained in:
Daniel Jasper 2016-02-29 12:26:20 +00:00
parent 6bb15021b3
commit 35ca66debf
2 changed files with 20 additions and 1 deletions

View File

@ -863,7 +863,9 @@ UnwrappedLineFormatter::format(const SmallVectorImpl<AnnotatedLine *> &Lines,
// If no token in the current line is affected, we still need to format
// affected children.
if (TheLine.ChildrenAffected)
format(TheLine.Children, DryRun);
for (const FormatToken *Tok = TheLine.First; Tok; Tok = Tok->Next)
if (!Tok->Children.empty())
format(Tok->Children, DryRun);
// Adapt following lines on the current indent level to the same level
// unless the current \c AnnotatedLine is not at the beginning of a line.

View File

@ -278,6 +278,23 @@ TEST_F(FormatTestSelective, IndividualStatementsOfNestedBlocks) {
" };\n"
"});",
0, 0));
EXPECT_EQ("SomeFunction(\n"
" [] {\n"
" int i;\n"
" return i;\n" // Format this line.
" },\n"
" [] {\n"
" return 2;\n" // Don't fix this.
" });",
format("SomeFunction(\n"
" [] {\n"
" int i;\n"
" return i;\n" // Format this line.
" },\n"
" [] {\n"
" return 2;\n" // Don't fix this.
" });",
40, 0));
}
TEST_F(FormatTestSelective, WrongIndent) {