diff --git a/lib/Format/UnwrappedLineFormatter.cpp b/lib/Format/UnwrappedLineFormatter.cpp index f65056907963ef6b3c944a3173e5a2b4932d16b9..d75eaf54a0848fad397757b9b866971dae8b91b9 100644 --- a/lib/Format/UnwrappedLineFormatter.cpp +++ b/lib/Format/UnwrappedLineFormatter.cpp @@ -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. diff --git a/unittests/Format/FormatTestSelective.cpp b/unittests/Format/FormatTestSelective.cpp index 699600c42d9fe04e4f883e8813f8ad0a9f96c99f..5885cadee621c87572f76b93af8ff28fdc43ab17 100644 --- a/unittests/Format/FormatTestSelective.cpp +++ b/unittests/Format/FormatTestSelective.cpp @@ -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) {