Have Range::overlapsWith use positive logic
Improved test to catch missing case.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188304 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Tooling/Refactoring.h b/include/clang/Tooling/Refactoring.h
index efac016..7ebac33 100644
--- a/include/clang/Tooling/Refactoring.h
+++ b/include/clang/Tooling/Refactoring.h
@@ -48,9 +48,7 @@
/// @{
/// \brief Whether this range overlaps with \p RHS or not.
bool overlapsWith(Range RHS) const {
- if ((Offset + Length) <= RHS.Offset || Offset >= (RHS.Offset + RHS.Length))
- return false;
- return true;
+ return Offset + Length > RHS.Offset && Offset < RHS.Offset + RHS.Length;
}
/// \brief Whether this range contains \p RHS or not.
diff --git a/unittests/Tooling/RefactoringTest.cpp b/unittests/Tooling/RefactoringTest.cpp
index 81f9f04..a88de1c 100644
--- a/unittests/Tooling/RefactoringTest.cpp
+++ b/unittests/Tooling/RefactoringTest.cpp
@@ -353,6 +353,7 @@
EXPECT_FALSE(Range(10, 10).overlapsWith(Range(0, 10)));
EXPECT_FALSE(Range(0, 10).overlapsWith(Range(10, 10)));
EXPECT_TRUE(Range(0, 10).overlapsWith(Range(2, 6)));
+ EXPECT_TRUE(Range(2, 6).overlapsWith(Range(0, 10)));
}
TEST(Range, contains) {