From: Manuel Klimek Date: Fri, 8 Feb 2013 19:53:32 +0000 (+0000) Subject: Fix indentation-detection at indent level 0. X-Git-Tag: llvmorg-3.3.0-rc1~5846 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d076dcd54f21c5bb93562e9fc8516c0668b72842;p=platform%2Fupstream%2Fllvm.git 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;'. llvm-svn: 174737 --- diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 0797fb8da4ad..299a8558b970 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -977,10 +977,10 @@ private: /// that level is unknown. unsigned GetIndent(const std::vector 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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index df0b2962f29c..a8c327a0d540 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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