Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destructor Tombstones #5318

Merged
merged 18 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions stl/inc/deque
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,18 @@ public:

_Deque_val() noexcept : _Map(), _Mapsize(0), _Myoff(0), _Mysize(0) {}

#if _MSVC_STL_DESTRUCTOR_TOMBSTONES
~_Deque_val() noexcept {
if constexpr (is_pointer_v<_Mapptr>) {
const auto _Tombstone{reinterpret_cast<_Mapptr>(_MSVC_STL_UINTPTR_TOMBSTONE_VALUE)};
_Map = _Tombstone;
_Mapsize = 0;
_Myoff = 0;
_Mysize = 0;
}
}
#endif // _MSVC_STL_DESTRUCTOR_TOMBSTONES

_Map_difference_type _Getblock(size_type _Off) const noexcept {
// NB: _Mapsize and _Block_size are guaranteed to be powers of 2
return static_cast<_Map_difference_type>((_Off / _Block_size) & (_Mapsize - 1));
Expand Down
9 changes: 9 additions & 0 deletions stl/inc/forward_list
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ public:

_Flist_val() noexcept : _Myhead() {} // initialize data

#if _MSVC_STL_DESTRUCTOR_TOMBSTONES
~_Flist_val() noexcept {
if constexpr (is_pointer_v<_Nodeptr>) {
const auto _Tombstone{reinterpret_cast<_Nodeptr>(_MSVC_STL_UINTPTR_TOMBSTONE_VALUE)};
_Myhead = _Tombstone;
}
}
#endif // _MSVC_STL_DESTRUCTOR_TOMBSTONES

_Nodeptr _Before_head() const noexcept { // return pointer to the "before begin" pseudo node
return pointer_traits<_Nodeptr>::pointer_to(reinterpret_cast<_Node&>(const_cast<_Nodeptr&>(_Myhead)));
}
Expand Down
10 changes: 10 additions & 0 deletions stl/inc/list
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,16 @@ public:

_List_val() noexcept : _Myhead(), _Mysize(0) {} // initialize data

#if _MSVC_STL_DESTRUCTOR_TOMBSTONES
~_List_val() noexcept {
if constexpr (is_pointer_v<_Nodeptr>) {
const auto _Tombstone{reinterpret_cast<_Nodeptr>(_MSVC_STL_UINTPTR_TOMBSTONE_VALUE)};
_Myhead = _Tombstone;
_Mysize = 0;
}
}
#endif // _MSVC_STL_DESTRUCTOR_TOMBSTONES

void _Orphan_ptr2(_Nodeptr _Ptr) noexcept { // orphan iterators with specified node pointers
#if _ITERATOR_DEBUG_LEVEL == 2
_Lockit _Lock(_LOCK_DEBUG);
Expand Down
17 changes: 17 additions & 0 deletions stl/inc/vector
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,19 @@ public:
_CONSTEXPR20 _Vector_val(pointer _First, pointer _Last, pointer _End) noexcept
: _Myfirst(_First), _Mylast(_Last), _Myend(_End) {}

#if _MSVC_STL_DESTRUCTOR_TOMBSTONES
_CONSTEXPR20 ~_Vector_val() noexcept {
if constexpr (is_pointer_v<pointer>) {
if (!_STD _Is_constant_evaluated()) {
const auto _Tombstone{reinterpret_cast<pointer>(_MSVC_STL_UINTPTR_TOMBSTONE_VALUE)};
_Myfirst = _Tombstone;
_Mylast = _Tombstone;
_Myend = _Tombstone;
}
}
}
#endif // _MSVC_STL_DESTRUCTOR_TOMBSTONES

_CONSTEXPR20 void _Swap_val(_Vector_val& _Right) noexcept {
this->_Swap_proxy_and_iterators(_Right);
swap(_Myfirst, _Right._Myfirst); // intentional ADL
Expand Down Expand Up @@ -2851,6 +2864,10 @@ public:
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alvbase, this->_Getal());
_Delete_plain_internal(_Alproxy, _STD exchange(this->_Myproxy, nullptr));
#endif // _ITERATOR_DEBUG_LEVEL != 0

#if _MSVC_STL_DESTRUCTOR_TOMBSTONES
_Mysize = 0;
#endif
}

_CONSTEXPR20 _Alvbase& _Getal() noexcept {
Expand Down
7 changes: 7 additions & 0 deletions stl/inc/xhash
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,13 @@ public:
#endif // _ENABLE_STL_INTERNAL_CHECK
}

#if _MSVC_STL_DESTRUCTOR_TOMBSTONES
~_Hash() noexcept {
_Mask = _Min_buckets - 1;
_Maxidx = _Min_buckets;
}
#endif // _MSVC_STL_DESTRUCTOR_TOMBSTONES

private:
void _Swap_val(_Hash& _Right) noexcept { // swap contents with equal allocator _Hash _Right
_List._Swap_val(_Right._List);
Expand Down
10 changes: 10 additions & 0 deletions stl/inc/xtree
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,16 @@ public:

_Tree_val() noexcept : _Myhead(), _Mysize(0) {}

#if _MSVC_STL_DESTRUCTOR_TOMBSTONES
~_Tree_val() noexcept {
if constexpr (is_pointer_v<_Nodeptr>) {
const auto _Tombstone{reinterpret_cast<_Nodeptr>(_MSVC_STL_UINTPTR_TOMBSTONE_VALUE)};
_Myhead = _Tombstone;
_Mysize = 0;
}
}
#endif // _MSVC_STL_DESTRUCTOR_TOMBSTONES

enum _Redbl { // colors for link to parent
_Red,
_Black
Expand Down