[llvm] Inline operator== and operator!= (PR #67958)

Giulio Eulisse via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 2 01:31:08 PDT 2023


https://github.com/ktf created https://github.com/llvm/llvm-project/pull/67958

Avoid triggering -Wnon-template-friend on newer GCC.

>From 77e9d0c050ecc998ab4c2485e6a284f835689c6e Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+ktf at users.noreply.github.com>
Date: Mon, 2 Oct 2023 10:27:50 +0200
Subject: [PATCH] Inline operator== and operator!=

Avoid triggering -Wnon-template-friend.
---
 llvm/include/llvm/ADT/PagedVector.h | 43 +++++++++++++----------------
 1 file changed, 19 insertions(+), 24 deletions(-)

diff --git a/llvm/include/llvm/ADT/PagedVector.h b/llvm/include/llvm/ADT/PagedVector.h
index 667bece6d718385..c96e0b20e2d33d7 100644
--- a/llvm/include/llvm/ADT/PagedVector.h
+++ b/llvm/include/llvm/ADT/PagedVector.h
@@ -209,36 +209,31 @@ template <typename T, size_t PageSize = 1024 / sizeof(T)> class PagedVector {
       return PagePtr[ElementIdx % PageSize];
     }
 
+    /// Equality operator.
     friend bool operator==(MaterializedIterator const &LHS,
-                           MaterializedIterator const &RHS);
+                           MaterializedIterator const &RHS) {
+      assert(LHS.PV == RHS.PV);
+      // Make sure we are comparing either end iterators or iterators pointing
+      // to materialized elements.
+      // It should not be possible to build two iterators pointing to non
+      // materialized elements.
+      assert(LHS.ElementIdx == LHS.PV->Size ||
+             (LHS.ElementIdx < LHS.PV->Size &&
+              LHS.PV->PageToDataPtrs[LHS.ElementIdx / PageSize]));
+      assert(RHS.ElementIdx == RHS.PV->Size ||
+             (RHS.ElementIdx < RHS.PV->Size &&
+              RHS.PV->PageToDataPtrs[RHS.ElementIdx / PageSize]));
+      return LHS.ElementIdx == RHS.ElementIdx;
+    }
+
     friend bool operator!=(MaterializedIterator const &LHS,
-                           MaterializedIterator const &RHS);
+                           MaterializedIterator const &RHS) {
+      return !(LHS == RHS);
+    }
 
     [[nodiscard]] size_t getIndex() const { return ElementIdx; }
   };
 
-  /// Equality operator.
-  friend bool operator==(MaterializedIterator const &LHS,
-                         MaterializedIterator const &RHS) {
-    assert(LHS.PV == RHS.PV);
-    // Make sure we are comparing either end iterators or iterators pointing
-    // to materialized elements.
-    // It should not be possible to build two iterators pointing to non
-    // materialized elements.
-    assert(LHS.ElementIdx == LHS.PV->Size ||
-           (LHS.ElementIdx < LHS.PV->Size &&
-            LHS.PV->PageToDataPtrs[LHS.ElementIdx / PageSize]));
-    assert(RHS.ElementIdx == RHS.PV->Size ||
-           (RHS.ElementIdx < RHS.PV->Size &&
-            RHS.PV->PageToDataPtrs[RHS.ElementIdx / PageSize]));
-    return LHS.ElementIdx == RHS.ElementIdx;
-  }
-
-  friend bool operator!=(MaterializedIterator const &LHS,
-                         MaterializedIterator const &RHS) {
-    return !(LHS == RHS);
-  }
-
   /// Iterators over the materialized elements of the vector.
   ///
   /// This includes all the elements belonging to allocated pages,



More information about the llvm-commits mailing list