diff options
-rw-r--r-- | lib/Format/Format.cpp | 4 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 13 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index fa62752fe6..e950fe6030 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -999,7 +999,9 @@ public: while (IndentForLevel.size() <= TheLine.Level) IndentForLevel.push_back(-1); IndentForLevel.resize(TheLine.Level + 1); - if (touchesRanges(TheLine) && TheLine.Type != LT_Invalid) { + bool WasMoved = + PreviousLineWasTouched && TheLine.First.FormatTok.NewlinesBefore == 0; + if (TheLine.Type != LT_Invalid && (WasMoved || touchesRanges(TheLine))) { unsigned LevelIndent = getIndent(IndentForLevel, TheLine.Level); unsigned Indent = LevelIndent; if (static_cast<int>(Indent) + Offset >= 0) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index c63d7566a9..90196afa62 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -168,6 +168,19 @@ TEST_F(FormatTest, RemovesTrailingWhitespaceOfFormattedLine) { EXPECT_EQ("int a;\nint b;", format("int a; \nint b;", 0, 0, getLLVMStyle())); } +TEST_F(FormatTest, ReformatsMovedLines) { + EXPECT_EQ( + "template <typename T> T *getFETokenInfo() const {\n" + " return static_cast<T *>(FETokenInfo);\n" + "}\n" + " int a; // <- Should not be formatted", + format( + "template<typename T>\n" + "T *getFETokenInfo() const { return static_cast<T*>(FETokenInfo); }\n" + " int a; // <- Should not be formatted", + 9, 5, getLLVMStyle())); +} + //===----------------------------------------------------------------------===// // Tests for control statements. //===----------------------------------------------------------------------===// |