diff options
-rw-r--r-- | lib/Format/Format.cpp | 15 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 3 |
2 files changed, 12 insertions, 6 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 347e31470d..f29308e509 100644 --- a/lib/Format/Format.cpp +++ b/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<int>(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<int>(LevelIndent) - Offset >= 0) + LevelIndent -= Offset; + IndentForLevel[TheLine.Level] = LevelIndent; + } } } return Whitespaces.generateReplacements(); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index e9520b618c..f1cef2a03d 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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 |