Skip to content

Commit 8456e0c

Browse files
authored
[ADT] Allow std::next to work on BitVector's set_bits_iterator (#80830)
Without this I would hit errors with libstdc++-12 like: /usr/include/c++/12/bits/stl_iterator_base_funcs.h:230:5: note: candidate template ignored: substitution failure [with _InputIterator = llvm::const_set_bits_iterator_impl<llvm::BitVector>]: argument may not have 'void' type next(_InputIterator __x, typename ^
1 parent e678e6e commit 8456e0c

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

llvm/include/llvm/ADT/BitVector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ template <typename BitVectorT> class const_set_bits_iterator_impl {
4242

4343
public:
4444
using iterator_category = std::forward_iterator_tag;
45-
using difference_type = void;
45+
using difference_type = std::ptrdiff_t;
4646
using value_type = int;
4747
using pointer = value_type*;
4848
using reference = value_type&;

llvm/unittests/ADT/BitVectorTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,9 @@ TYPED_TEST(BitVectorTest, EmptyVectorGetData) {
11431143
}
11441144

11451145
TYPED_TEST(BitVectorTest, Iterators) {
1146+
TypeParam Singleton(1, true);
1147+
EXPECT_EQ(std::next(Singleton.set_bits_begin()), Singleton.set_bits_end());
1148+
11461149
TypeParam Filled(10, true);
11471150
EXPECT_NE(Filled.set_bits_begin(), Filled.set_bits_end());
11481151
unsigned Counter = 0;

0 commit comments

Comments
 (0)