Fix indentation-detection at indent level 0.
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
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 0797fb8..299a855 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -977,10 +977,10 @@
/// 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;
}
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index df0b296..a8c327a 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -2593,7 +2593,12 @@
" b;\n"
"}\n"
"}", 22, 2, getLLVMStyle()));
-}
+ EXPECT_EQ(" {\n"
+ " a;\n"
+ " }", format(" {\n"
+ "a;\n"
+ " }", 4, 2, getLLVMStyle()));
+}
} // end namespace tooling
} // end namespace clang