diff options
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 5 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 16 |
2 files changed, 20 insertions, 1 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index e5afa1264ab..07109daf6f9 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -350,7 +350,10 @@ void UnwrappedLineParser::parseLevel(bool HasOpeningBrace) { break; case tok::kw_default: { unsigned StoredPosition = Tokens->getPosition(); - FormatToken *Next = Tokens->getNextToken(); + FormatToken *Next; + do { + Next = Tokens->getNextToken(); + } while (Next && Next->is(tok::comment)); FormatTok = Tokens->setPosition(StoredPosition); if (Next && Next->isNot(tok::colon)) { // default not followed by ':' is not a case label; treat it like diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index d73b1d82671..a603012ccf4 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -1145,6 +1145,22 @@ TEST_F(FormatTest, ShortCaseLabels) { " break;\n" "}", Style); + Style.ColumnLimit = 80; + Style.AllowShortCaseLabelsOnASingleLine = false; + Style.IndentCaseLabels = true; + EXPECT_EQ("switch (n) {\n" + " default /*comments*/:\n" + " return true;\n" + " case 0:\n" + " return false;\n" + "}", + format("switch (n) {\n" + "default/*comments*/:\n" + " return true;\n" + "case 0:\n" + " return false;\n" + "}", + Style)); } TEST_F(FormatTest, FormatsLabels) { |