From f758bc7125d59bca12bb6c5f1d3c9025f395710e 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188304 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Tooling/Refactoring.h | 4 +--- unittests/Tooling/RefactoringTest.cpp | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/clang/Tooling/Refactoring.h b/include/clang/Tooling/Refactoring.h index efac016b19..7ebac33a9a 100644 --- a/include/clang/Tooling/Refactoring.h +++ b/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/unittests/Tooling/RefactoringTest.cpp b/unittests/Tooling/RefactoringTest.cpp index 81f9f040ae..a88de1c9f4 100644 --- a/unittests/Tooling/RefactoringTest.cpp +++ b/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.50.1