Skip to content

Fix double destructor call in (un)buffered_channel::iterator::operator++#342

Open
eoan-ermine wants to merge 4 commits into
boostorg:developfrom
eoan-ermine:issue/291
Open

Fix double destructor call in (un)buffered_channel::iterator::operator++#342
eoan-ermine wants to merge 4 commits into
boostorg:developfrom
eoan-ermine:issue/291

Conversation

@eoan-ermine
Copy link
Copy Markdown
Contributor

increment_() already calls destructor

Closes #291

Copilot AI review requested due to automatic review settings June 1, 2026 12:12
@eoan-ermine
Copy link
Copy Markdown
Contributor Author

Oh. There's already #339 . Sorry, didn't notice

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR addresses issue 291 around channel iteration by adjusting iterator element-lifetime handling and adding regression tests to ensure range-for iteration works with non-trivial types (e.g., std::shared_ptr).

Changes:

  • Added new regression tests (test_issue_291) for both buffered and unbuffered channels using std::shared_ptr<int> and range-for iteration.
  • Modified channel iterators to stop explicitly destroying the stored value_type in operator++() (likely to prevent double-destruction / invalid lifetime transitions).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
test/test_unbuffered_channel_post.cpp Adds a regression test that iterates an unbuffered_channel<std::shared_ptr<int>> via range-for and validates values.
test/test_buffered_channel_post.cpp Adds a matching regression test for buffered_channel<std::shared_ptr<int>>.
include/boost/fiber/unbuffered_channel.hpp Removes explicit destruction of iterator’s in-place value_type on increment.
include/boost/fiber/buffered_channel.hpp Removes explicit destruction of iterator’s in-place value_type on increment.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +451 to +454
auto it = vec.begin();
BOOST_CHECK_EQUAL(256, *(*it));
it++;
BOOST_CHECK_EQUAL(512, *(*it));
Comment on lines +497 to +500
auto it = vec.begin();
BOOST_CHECK_EQUAL(256, *(*it));
it++;
BOOST_CHECK_EQUAL(512, *(*it));
Comment on lines +490 to +491
void test_issue_291() {
boost::fibers::buffered_channel<std::shared_ptr<int>> chan(16);
Comment on lines 446 to 449
iterator & operator++() {
reinterpret_cast< value_type * >( std::addressof( storage_) )->~value_type();
increment_();
return * this;
}
Copy link
Copy Markdown
Contributor Author

@eoan-ermine eoan-ermine Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, slop machine. What do you suggest, call destructor twice or remove destructor call in increment_?

Comment on lines 411 to 414
iterator & operator++() {
reinterpret_cast< value_type * >( std::addressof( storage_) )->~value_type();
increment_();
return * this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

buffered_channel calls deleter twice when using iterators

2 participants