]> granicus.if.org Git - clang/commitdiff
Fix indentation-detection at indent level 0.
authorManuel Klimek <klimek@google.com>
Fri, 8 Feb 2013 19:53:32 +0000 (19:53 +0000)
committerManuel Klimek <klimek@google.com>
Fri, 8 Feb 2013 19:53:32 +0000 (19:53 +0000)
This correctly formats:
  {
    a;
  }
where { is incorrectly indented by 2, but is at level 0, when
reformatting only 'a;'.

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

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

index 0797fb8da4ad6a675ef4869cd723bb4df1d110dd..299a8558b9708703c15d85b489e758956a7e8547 100644 (file)
@@ -977,10 +977,10 @@ private:
   /// that level is unknown.
   unsigned GetIndent(const std::vector<int> IndentForLevel,
                      unsigned Level) {
-    if (Level == 0)
-      return 0;
     if (IndentForLevel[Level] != -1)
       return IndentForLevel[Level];
+    if (Level == 0)
+      return 0;
     return GetIndent(IndentForLevel, Level - 1) + 2;
   }
 
index df0b2962f29c7d6bd9b0f16276abd4fa4615a09a..a8c327a0d540e246c9bd6cea1516977dbdfeffca 100644 (file)
@@ -2593,7 +2593,12 @@ TEST_F(FormatTest, ReformatRegionAdjustsIndent) {
                         "           b;\n"
                         "}\n"
                         "}", 22, 2, getLLVMStyle()));
-} 
+  EXPECT_EQ("  {\n"
+            "    a;\n"
+            "  }", format("  {\n"
+                          "a;\n"
+                          "  }", 4, 2, getLLVMStyle()));
+}
 
 } // end namespace tooling
 } // end namespace clang