<memory>: Make algorithms properly destroy objects in constant evaluation by frederick-vs-ja · Pull Request #5449 · microsoft/STL (original) (raw)

Currently, MSVC STL's destroying algorithms skip ranges whose element types are trivially destructible. This is slightly non-conforming, because further access to the destroyed objects should cause core language UB and in turn cause constant evaluation failure.

This PR makes std::(ranges::)destroy(_at, _n) always destroy objects during constant evaluation. The behavior difference is currently only observable by Clang due to bugs of MSVC (DevCom-10642767) and EDG (DevCom-10896316).

The allocator-aware _Destroy_range is not yet touched, because any attempt to access an element destroyed by that overload will raise library UB first.

Related to #5225, although the "vectorized implementation" is no-op in these algorithms. The change about if consteval are dropped. See the review comments.