diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Format/Format.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 2 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 26 |
3 files changed, 30 insertions, 2 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 4b994e3b759..999d6210fcd 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -952,10 +952,10 @@ public: return false; } break; - case tok::l_paren: { + case tok::l_paren: if (!parseParens()) return false; - } break; + break; case tok::l_square: if (!parseSquare()) return false; diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 89ab0ed169d..1f71b5b7dac 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -487,6 +487,8 @@ void UnwrappedLineParser::parseLabel() { --Line->Level; if (FormatTok.Tok.is(tok::l_brace)) { parseBlock(); + if (FormatTok.Tok.is(tok::kw_break)) + parseStructuralElement(); // "break;" after "}" goes on the same line. } addUnwrappedLine(); Line->Level = OldLineLevel; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index c3fef1d4015..2a2bb3fe6d9 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -274,6 +274,32 @@ TEST_F(FormatTest, FormatsSwitchStatement) { " break;\n" "}\n" "}"); + verifyFormat("switch (x) {\n" + "case 1: {\n" + " f();\n" + " {\n" + " g();\n" + " h();\n" + " }\n" + " break;\n" + "}\n" + "}"); + verifyFormat("switch (x) {\n" + "case 1: {\n" + " f();\n" + " if (foo) {\n" + " g();\n" + " h();\n" + " }\n" + " break;\n" + "}\n" + "}"); + verifyFormat("switch (x) {\n" + "case 1: {\n" + " f();\n" + " g();\n" + "} break;\n" + "}"); verifyFormat("switch (test)\n" " ;"); verifyGoogleFormat("switch (x) {\n" |