From: Daniel Jasper Date: Tue, 12 Feb 2013 16:51:23 +0000 (+0000) Subject: Fix bug in the adjustment to existing lines. X-Git-Tag: llvmorg-3.3.0-rc1~5620 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2204562acdc8eb94c2a2b7088e2fc0dc7a0f70e3;p=platform%2Fupstream%2Fllvm.git Fix bug in the adjustment to existing lines. Before (if only the second line was reformatted): void f() {} void g() {} After: void f() {} void g() {} llvm-svn: 174978 --- diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 347e31470d5a..f29308e509c7 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -957,12 +957,15 @@ public: TheLine.Last->FormatTok.Tok.getLocation()) + Lex.MeasureTokenLength(TheLine.Last->FormatTok.Tok.getLocation(), SourceMgr, Lex.getLangOpts()) - 1; - unsigned Indent = SourceMgr.getSpellingColumnNumber( - TheLine.First.FormatTok.Tok.getLocation()) - 1; - unsigned LevelIndent = Indent; - if (static_cast(LevelIndent) - Offset >= 0) - LevelIndent -= Offset; - IndentForLevel[TheLine.Level] = LevelIndent; + if (TheLine.First.FormatTok.NewlinesBefore > 0 || + TheLine.First.FormatTok.IsFirst) { + unsigned Indent = SourceMgr.getSpellingColumnNumber( + TheLine.First.FormatTok.Tok.getLocation()) - 1; + unsigned LevelIndent = Indent; + if (static_cast(LevelIndent) - Offset >= 0) + LevelIndent -= Offset; + IndentForLevel[TheLine.Level] = LevelIndent; + } } } return Whitespaces.generateReplacements(); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index e9520b618c38..f1cef2a03d13 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -2660,6 +2660,9 @@ TEST_F(FormatTest, ReformatRegionAdjustsIndent) { " }", format(" {\n" "a;\n" " }", 4, 2, getLLVMStyle())); + EXPECT_EQ("void f() {}\n" + "void g() {}", format("void f() {}\n" + "void g() {}", 13, 0, getLLVMStyle())); } } // end namespace tooling