r177420 - Fix indentation for case: // comment.

Daniel Jasper djasper at google.com
Tue Mar 19 11:33:58 PDT 2013


Author: djasper
Date: Tue Mar 19 13:33:58 2013
New Revision: 177420

URL: http://llvm.org/viewvc/llvm-project?rev=177420&view=rev
Log:
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();
  }
}

Modified:
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=177420&r1=177419&r2=177420&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Tue Mar 19 13:33:58 2013
@@ -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.

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=177420&r1=177419&r2=177420&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Mar 19 13:33:58 2013
@@ -432,6 +432,15 @@ TEST_F(FormatTest, FormatsSwitchStatemen
                "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"





More information about the cfe-commits mailing list