From 2bd32ca92a1782fa2938b49993812750d90c0a9b Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 19 Mar 2013 18:33:58 +0000 Subject: [PATCH] Fix indentation for case: // comment. Before: switch (x) { case 1: // Do amazing stuff { g(); f(); } } After: switch (x) { case 1: // Do amazing stuff { g(); f(); } } llvm-svn: 177420 --- clang/lib/Format/UnwrappedLineParser.cpp | 2 +- clang/unittests/Format/FormatTest.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index cdd77759fd2c..a438a53c370f 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -576,7 +576,7 @@ void UnwrappedLineParser::parseLabel() { unsigned OldLineLevel = Line->Level; if (Line->Level > 0) --Line->Level; - if (FormatTok.Tok.is(tok::l_brace)) { + if (CommentsBeforeNextToken.empty() && FormatTok.Tok.is(tok::l_brace)) { parseBlock(/*MustBeDeclaration=*/ false); if (FormatTok.Tok.is(tok::kw_break)) parseStructuralElement(); // "break;" after "}" goes on the same line. diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index a3afbee916e9..a940f7092fc4 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -432,6 +432,15 @@ TEST_F(FormatTest, FormatsSwitchStatement) { "case 1:\n" " f();\n" "}"); + verifyFormat("switch (x) {\n" + "case 1:\n" + " // Do amazing stuff\n" + " {\n" + " f();\n" + " g();\n" + " }\n" + " break;\n" + "}"); verifyGoogleFormat("switch (x) {\n" " case 1:\n"