From 52635ff9fb530dfdfc6a94e52a2270bf1bb8346b Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Fri, 8 Feb 2013 19:53:32 +0000 Subject: [PATCH] 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 --- lib/Format/Format.cpp | 4 ++-- unittests/Format/FormatTest.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 0797fb8da4..299a8558b9 100644 --- a/lib/Format/Format.cpp +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index df0b2962f2..a8c327a0d5 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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 -- 2.40.0