[llvm] [ADT] use correct iterator_facade_base for SmallSetIterator (PR #180967)

Fedor Sergeev via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 11 08:23:14 PST 2026


https://github.com/Theodor created https://github.com/llvm/llvm-project/pull/180967

SmallSetIterator is inherently constant. Now it is properly expressed through passing const to PointerT/ReferenceT parameters of its base class. This way wrappers like make_filter_range do not try to treat SmallSetIterator as non-constant.

Fixes #179139

>From ad2d4226ce724f45235d597c740ca1bd980b50a7 Mon Sep 17 00:00:00 2001
From: Fedor Sergeev <fedor.v.sergeev at gmail.com>
Date: Wed, 11 Feb 2026 19:13:07 +0300
Subject: [PATCH] [ADT] use correct iterator_facade_base for SmallSetIterator

SmallSetIterator is inherently constant. Now it is properly expressed
through passing const to PointerT/ReferenceT parameters of its base class.
This way wrappers like make_filter_range do not try to treat SmallSetIterator
as non-constant.

Fixes #179139
---
 llvm/include/llvm/ADT/SmallSet.h    |  3 ++-
 llvm/unittests/ADT/SmallSetTest.cpp | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/llvm/include/llvm/ADT/SmallSet.h b/llvm/include/llvm/ADT/SmallSet.h
index 3ca833f15eed3..efbd66bb4d5b2 100644
--- a/llvm/include/llvm/ADT/SmallSet.h
+++ b/llvm/include/llvm/ADT/SmallSet.h
@@ -32,7 +32,8 @@ namespace llvm {
 template <typename T, unsigned N, typename C>
 class SmallSetIterator
     : public iterator_facade_base<SmallSetIterator<T, N, C>,
-                                  std::forward_iterator_tag, T> {
+                                  std::forward_iterator_tag, T, std::ptrdiff_t,
+                                  const T *, const T &> {
 private:
   using SetIterTy = typename std::set<T, C>::const_iterator;
   using VecIterTy = typename SmallVector<T, N>::const_iterator;
diff --git a/llvm/unittests/ADT/SmallSetTest.cpp b/llvm/unittests/ADT/SmallSetTest.cpp
index 1d1e84ba7fcfd..ac99bb2c66495 100644
--- a/llvm/unittests/ADT/SmallSetTest.cpp
+++ b/llvm/unittests/ADT/SmallSetTest.cpp
@@ -300,3 +300,13 @@ TEST(SmallSetTest, Contains) {
   EXPECT_TRUE(Set.contains(1));
   EXPECT_TRUE(Set.contains(2));
 }
+
+TEST(SmallSetTest, FilterPositive) {
+  SmallSet<int, 4> Set({3, -1, 2, -4});
+  auto PositiveRange = make_filter_range(Set, [](int V) { return V > 0; });
+  auto PositiveIt = PositiveRange.begin();
+  EXPECT_EQ(*PositiveIt, 3);
+  ++PositiveIt;
+  EXPECT_EQ(*PositiveIt, 2);
+  EXPECT_EQ(PositiveIt, PositiveRange.end());
+}



More information about the llvm-commits mailing list