Created on 2023-01-30.00:00:00 last changed 12 months ago
Proposed resolution:
This wording is relative to N4928.
Modify [specialized.algorithms.general], General, as indicated:
-4- Some algorithms specified in [specialized.algorithms] make use of the exposition-only function voidify:
template<class T> constexpr void* voidify(T& obj) noexcept { return
const_cast<void*>(static_cast<const volatile void*>(addressof(obj))); }
[ 2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Immediate → WP. ]
[ Issaquah 2023-02-06; LWG ]
Casey noted:
The claimed benefit is allowing the uninitialized_xxx algorithms to create objects of const and/or volatile type, which they cannot otherwise do since they deduce the type of object to be created from the reference type of the pertinent iterator. Creating const objects has some (marginal?) benefits over using const pointers to mutable objects. For example, their non-mutable members cannot be modified via casting away const without undefined behavior. A unit test might take advantage of this behavior to force a compiler to diagnose such undefined behavior in a constant expression.
The issue submitter was aware of this, but an open Core issue, CWG 2514, would invalidate that benefit. If accepted, objects with dynamic storage duration (such as those created by std::construct_as and the std::uninitialized_xxx algorithms) would never be const objects, so casting away the const would not be undefined. So implicitly removing const in voidify would still allow modifying "truly const" objects (resulting in undefined behaviour), without being able to create "truly const" objects in locations where that actually is safe. If CWG 2514 is accepted, the voidify behaviour would be all downside.
LWG requested removing the remaining casts from the proposed resolution, relying on an implicit conversion to void* instead. Move to Immediate for C++23.
Previous resolution [SUPERSEDED]:
This wording is relative to N4928.
Modify [specialized.algorithms.general], General, as indicated:
-4- Some algorithms specified in [specialized.algorithms] make use of the exposition-only function voidify:
template<class T> constexpr void* voidify(T& obj) noexcept { return
const_cast<void*>(static_cast<const volatilevoid*>(addressof(obj))); }
This is the resolution for NB comment GB-121
The voidify helper breaks const-correctness, for no tangible benefit. C++20 ballot comment US 215 also suggested removing it, but failed to achieve consensus. That should be reconsidered.
The only claimed benefits are:
History | |||
---|---|---|---|
Date | User | Action | Args |
2023-11-22 15:47:43 | admin | set | status: wp -> c++23 |
2023-02-13 11:31:32 | admin | set | messages: + msg13397 |
2023-02-13 11:31:32 | admin | set | status: immediate -> wp |
2023-02-10 14:34:22 | admin | set | messages: + msg13332 |
2023-02-10 14:34:22 | admin | set | status: new -> immediate |
2023-01-30 21:27:38 | admin | set | messages: + msg13239 |
2023-01-30 00:00:00 | admin | create |