Destructor Tombstones by StephanTLavavej 路 Pull Request #5318 路 microsoft/STL (original) (raw)

@StephanTLavavej

@StephanTLavavej

@StephanTLavavej

This is special because of the Small String Optimization. In small mode, the string would be usable, so we need large mode for the tombstone to have any effect.

I'm setting _Mysize to zero, to work with hardened preconditions as usual. For the capacity _Myres, I'm using the first value that basic_string would use when entering large mode, as it has a "roundup mask".

_Large_mode_engaged() returns _Myres > _Small_string_capacity, so _Small_string_capacity + 1 would be sufficient, but it seems safer to use the value that basic_string would ordinarily use, as this is less likely to confuse basic_string logic now and in the future. Only the tombstone pointer needs to be impossible.

@StephanTLavavej

@StephanTLavavej

@StephanTLavavej

The Small Functor Optimization is much easier to deal with than basic_string. _Local() returns _Getimpl() == static_cast<const void*>(&_Mystorage), so the tombstone pointer will be detected as large.

@StephanTLavavej

@StephanTLavavej

Comment that _Tidy_deallocate() already sets _Mysize = 0;.

@StephanTLavavej

With a comment explaining why we're using _Small mode.

@StephanTLavavej

This makes the destructor behave like reset().

Setting it to empty will work with precondition hardening to prevent access to the object.

We should not attempt to scribble over T's bytes.

@StephanTLavavej

@StephanTLavavej

Everything goes through this pseudo-vtable.

@StephanTLavavej

__ExceptionPtrDestroy() calls ~shared_ptr<const _EXCEPTION_RECORD>(), but it's separately compiled.

@StephanTLavavej

@StephanTLavavej

Add an #error for the future when we enable destructor tombstones by default.

Update the comments to clarify how we feel about this usage.

Add missing alignas to the buffers - we were being very bad kitties.

@StephanTLavavej