From c514848d1bbdaa0f932bf0787e2daa740dbfdc6b Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Tue, 13 Aug 2013 18:11:16 +0000 Subject: [PATCH] Have Range::overlapsWith use positive logic Improved test to catch missing case. llvm-svn: 188304 --- clang/include/clang/Tooling/Refactoring.h | 4 +--- clang/unittests/Tooling/RefactoringTest.cpp | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Tooling/Refactoring.h b/clang/include/clang/Tooling/Refactoring.h index efac016b199b..7ebac33a9a29 100644 --- a/clang/include/clang/Tooling/Refactoring.h +++ b/clang/include/clang/Tooling/Refactoring.h @@ -48,9 +48,7 @@ public: /// @{ /// \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/clang/unittests/Tooling/RefactoringTest.cpp b/clang/unittests/Tooling/RefactoringTest.cpp index 81f9f040aeb7..a88de1c9f456 100644 --- a/clang/unittests/Tooling/RefactoringTest.cpp +++ b/clang/unittests/Tooling/RefactoringTest.cpp @@ -353,6 +353,7 @@ TEST(Range, overlaps) { 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) { -- 2.34.1