shared_ptr operator < compares managed pointers instead of stored pointers
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start with the operator< and owner_before implementations shown in the issue, then compare their behavior with the linked minimal aliasing-constructor reproduction and the documented std::shared_ptr comparison semantics. Done means the comparison behavior and its documentation consistently reflect the intended stored-pointer semantics, with regression coverage for the reported case.
Written by the indexing model from the issue text.
Description
operator < of boost::shared_ptr compares the managed pointers:
template<class T, class U> inline bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b) BOOST_SP_NOEXCEPT
{
return a.owner_before( b );
}
template<class Y> bool owner_before( shared_ptr<Y> const & rhs ) const BOOST_SP_NOEXCEPT
{
return pn < rhs.pn;
}
This is also documented as
under the equivalence relation defined by operator<, !(a < b) && !(b < a), two shared_ptr instances are equivalent if and only if they share ownership or are both empty.
However, std::shared_ptr compares the stored pointers. Comparing the managed pointers defeats the purpose of the aliasing constructor and is asymmetrical to operator==, which does compare the stored pointers. See https://en.cppreference.com/w/cpp/memory/shared_ptr/operator_cmp:
In all cases, it is the stored pointer (the one returned by get()) that is compared, rather than the managed pointer (the one passed to the deleter when use_count goes to zero). The two pointers may differ in a shared_ptr created using the aliasing constructor.
See a minimal repro here: https://godbolt.org/z/xon8cxnss
- Dominant language
- C++
- Stars
- 111
- Forks
- 116
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/smart_ptr
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
All issues in boostorg/smart_ptr
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100