This revision was automatically updated to reflect the committed changes. Closed by commit rL341284: Fix Bug 38713: clang-format mishandles a short block after "default:" in a… (authored by JonasToth, committed by ). Herald added a subscriber: llvm-commits.
Changed prior to commit: https://reviews.llvm.org/D51294?vs=162989&id=163639#toc Repository: rL LLVM https://reviews.llvm.org/D51294 Files: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp cfe/trunk/unittests/Format/FormatTest.cpp Index: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp +++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp @@ -483,6 +483,12 @@ if (Line.First->isOneOf(tok::kw_else, tok::kw_case) || (Line.First->Next && Line.First->Next->is(tok::kw_else))) return 0; + // default: in switch statement + if (Line.First->is(tok::kw_default)) { + const FormatToken *Tok = Line.First->getNextNonComment(); + if (Tok && Tok->is(tok::colon)) + return 0; + } if (Line.First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_do, tok::kw_try, tok::kw___try, tok::kw_catch, tok::kw___finally, tok::kw_for, tok::r_brace, Keywords.kw___except)) { Index: cfe/trunk/unittests/Format/FormatTest.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -999,6 +999,24 @@ " }\n" "});", getLLVMStyle())); + EXPECT_EQ("switch (n) {\n" + "case 0: {\n" + " return false;\n" + "}\n" + "default: {\n" + " return true;\n" + "}\n" + "}", + format("switch (n)\n" + "{\n" + "case 0: {\n" + " return false;\n" + "}\n" + "default: {\n" + " return true;\n" + "}\n" + "}", + getLLVMStyle())); verifyFormat("switch (a) {\n" "case (b):\n" " return;\n"
Index: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp +++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp @@ -483,6 +483,12 @@ if (Line.First->isOneOf(tok::kw_else, tok::kw_case) || (Line.First->Next && Line.First->Next->is(tok::kw_else))) return 0; + // default: in switch statement + if (Line.First->is(tok::kw_default)) { + const FormatToken *Tok = Line.First->getNextNonComment(); + if (Tok && Tok->is(tok::colon)) + return 0; + } if (Line.First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_do, tok::kw_try, tok::kw___try, tok::kw_catch, tok::kw___finally, tok::kw_for, tok::r_brace, Keywords.kw___except)) { Index: cfe/trunk/unittests/Format/FormatTest.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -999,6 +999,24 @@ " }\n" "});", getLLVMStyle())); + EXPECT_EQ("switch (n) {\n" + "case 0: {\n" + " return false;\n" + "}\n" + "default: {\n" + " return true;\n" + "}\n" + "}", + format("switch (n)\n" + "{\n" + "case 0: {\n" + " return false;\n" + "}\n" + "default: {\n" + " return true;\n" + "}\n" + "}", + getLLVMStyle())); verifyFormat("switch (a) {\n" "case (b):\n" " return;\n"
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits