Skip to content

Commit

Permalink
common/bit_vector: fix iterator vs reference constness confusion
Browse files Browse the repository at this point in the history
T (ConstIterator or Iterator) is confused with const T here:
IteratorImpl dereference operator is wrongly overloaded on const
and returns Reference instead of ConstReference for ConstIterator.
This then fails inside bufferlist bowels because Reference is
incompatible with bufferlist::const_iterator.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
  • Loading branch information
idryomov committed Jan 20, 2024
1 parent 232ad1a commit 45d5345
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/common/bit_vector.hpp
Expand Up @@ -83,7 +83,7 @@ class BitVector
};

public:
template <typename BitVectorT, typename DataIterator>
template <typename BitVectorT, typename DataIteratorT, typename ReferenceT>
class IteratorImpl {
private:
friend class BitVector;
Expand All @@ -94,7 +94,7 @@ class BitVector
// cached derived values
uint64_t m_index = 0;
uint64_t m_shift = 0;
DataIterator m_data_iterator;
DataIteratorT m_data_iterator;

IteratorImpl(BitVectorT *bit_vector, uint64_t offset)
: m_bit_vector(bit_vector),
Expand Down Expand Up @@ -145,17 +145,15 @@ class BitVector
return (m_offset != rhs.m_offset || m_bit_vector != rhs.m_bit_vector);
}

inline ConstReference operator*() const {
return ConstReference(m_data_iterator, m_shift);
}
inline Reference operator*() {
return Reference(m_data_iterator, m_shift);
inline ReferenceT operator*() const {
return ReferenceT(m_data_iterator, m_shift);
}
};

typedef IteratorImpl<const BitVector,
bufferlist::const_iterator> ConstIterator;
typedef IteratorImpl<BitVector, bufferlist::iterator> Iterator;
bufferlist::const_iterator,
ConstReference> ConstIterator;
typedef IteratorImpl<BitVector, bufferlist::iterator, Reference> Iterator;

static const uint32_t BLOCK_SIZE;
static const uint8_t BIT_COUNT = _bit_count;
Expand Down

0 comments on commit 45d5345

Please sign in to comment.