]> granicus.if.org Git - clang/commitdiff
clang-format: Fix bad indentation of nested blocks.
authorDaniel Jasper <djasper@google.com>
Fri, 29 Nov 2013 08:46:20 +0000 (08:46 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 29 Nov 2013 08:46:20 +0000 (08:46 +0000)
Before:
  DEBUG(  //
  { f(); });

After:
  DEBUG(  //
      { f(); });

Also add additional test to selected formatting of individual statements
in nested blocks.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195952 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTest.cpp

index a8891fcc2f881489f223e8443ee2a82ff6f27a7c..c2122ffb7d3683019c3d8881b0efc230990b3115 100644 (file)
@@ -340,7 +340,8 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
     Penalty += Style.PenaltyBreakFirstLessLess;
 
   if (Current.is(tok::l_brace) && Current.BlockKind == BK_Block) {
-    State.Column = State.FirstIndent;
+    State.Column =
+        State.ParenLevel == 0 ? State.FirstIndent : State.Stack.back().Indent;
   } else if (Current.isOneOf(tok::r_brace, tok::r_square)) {
     if (Current.closesBlockTypeList(Style) ||
         (Current.MatchingParen &&
index d809421a41f48c060e3010d24a3b39cfaa602271..e1960d290f8e0ad6c409bbc9ee0a1630b49738b7 100644 (file)
@@ -2465,6 +2465,14 @@ TEST_F(FormatTest, LayoutNestedBlocks) {
                "  somethingelse();\n"
                "});",
                getLLVMStyleWithColumns(40));
+  verifyFormat("DEBUG( //\n"
+               "    { f(); }, a);");
+  verifyFormat("DEBUG( //\n"
+               "    {\n"
+               "      f(); //\n"
+               "    },\n"
+               "    a);");
+
   EXPECT_EQ("call(parameter, {\n"
             "  something();\n"
             "  // Comment too\n"
@@ -2532,6 +2540,15 @@ TEST_F(FormatTest, IndividualStatementsOfNestedBlocks) {
                    "  int        j;\n"
                    "}   )  ;",
                    41, 1, getLLVMStyle()));
+  EXPECT_EQ("DEBUG(   {\n"
+            "    int        i;\n"
+            "    int j;\n"
+            "}   )  ;",
+            format("DEBUG(   {\n"
+                   "    int        i;\n"
+                   "    int        j;\n"
+                   "}   )  ;",
+                   41, 1, getLLVMStyle()));
   EXPECT_EQ("DEBUG({\n"
             "  int i;\n"
             "  int j;\n"