diff options
| author | Manuel Klimek <klimek@google.com> | 2013-02-08 19:53:32 +0000 |
|---|---|---|
| committer | Manuel Klimek <klimek@google.com> | 2013-02-08 19:53:32 +0000 |
| commit | d076dcd54f21c5bb93562e9fc8516c0668b72842 (patch) | |
| tree | 5e0abaaa178d27ac2ac43f8358be4d7eaad638a7 /clang | |
| parent | ca3ed7230de97dc0b54dc6f7b576dc1d6bf097d0 (diff) | |
| download | bcm5719-llvm-d076dcd54f21c5bb93562e9fc8516c0668b72842.tar.gz bcm5719-llvm-d076dcd54f21c5bb93562e9fc8516c0668b72842.zip | |
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
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Format/Format.cpp | 4 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 7 |
2 files changed, 8 insertions, 3 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 0797fb8da4a..299a8558b97 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<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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index df0b2962f29..a8c327a0d54 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 |

