diff options
-rw-r--r-- | lib/Format/Format.cpp | 7 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 5 |
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 67ca928a1a..63edc6e23e 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -1135,6 +1135,13 @@ public: deriveLocalStyle(); for (unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) { Annotator.calculateFormattingInformation(AnnotatedLines[i]); + + // Adapt level to the next line if this is a comment. + // FIXME: Can/should this be done in the UnwrappedLineParser? + if (i + 1 != e && AnnotatedLines[i].First.is(tok::comment) && + AnnotatedLines[i].First.Children.empty() && + AnnotatedLines[i + 1].First.isNot(tok::r_brace)) + AnnotatedLines[i].Level = AnnotatedLines[i + 1].Level; } std::vector<int> IndentForLevel; bool PreviousLineWasTouched = false; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 79163a6818..17aeacae5c 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -427,6 +427,11 @@ TEST_F(FormatTest, FormatsSwitchStatement) { "default: {\n" " // Do nothing.\n" "}"); + verifyFormat("switch (x) {\n" + "// if 1, do f()\n" + "case 1:\n" + " f();\n" + "}"); verifyGoogleFormat("switch (x) {\n" " case 1:\n" |