Skip to content

Fix weak_ptr conversions, preserving control blocks for expired objects - #1104

Merged
Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:masterfrom
StephanTLavavej:weak_ptr
Aug 1, 2020
Merged

Fix weak_ptr conversions, preserving control blocks for expired objects#1104
Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:masterfrom
StephanTLavavej:weak_ptr

Conversation

@StephanTLavavej

Copy link
Copy Markdown
Member

Fixes #1102. This adds a few comments to the product code, explaining what's going on. Then, I enhanced our existing test for weak_ptr conversions to test owner_before and then use owner_before to test that control blocks are preserved. Finally, I added a small test for the behavior of virtual inheritance conversions before the object expired, since we weren't actually testing that.

Performance note: it would be possible to detect T* to const T* and avoid the _Incref_nz (which we did before this PR too, in the form of _Other.lock()); I could file an issue about that after merging this PR if anyone is interested. At this time, we don't know if it's possible to detect virtual base traversal in general, without a compiler builtin.

Comment thread stl/inc/memory
Comment thread tests/std/tests/Dev10_851347_weak_ptr_virtual_inheritance/test.cpp
Comment thread stl/inc/memory Outdated
Comment thread stl/inc/memory Outdated
Comment thread stl/inc/memory Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working high priority Important!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<memory>: weak_ptr conversions don't preserve control blocks for expired objects

3 participants