q17::uninitialized_value_construct: use C++17/20 semantics of voidify

While LWG 3870 changed the const/static_cast'ing for C++23, this is
q17, so use the C++17/20 semantics of casting away const- and
volatile-ness.

Found in API-review.

Amends 364ac13a79a8fff0447a62e9af5588db397c0bfd.

Change-Id: Ie11589cbc96b8c3c36deaa6101a897f527d92a46
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit c05982fda39bbfa9fa3641c7e5938f204a8b1bf5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-01-18 10:37:31 +01:00 committed by Qt Cherry-pick Bot
parent 398c576037
commit aefd124efa

View File

@ -16,6 +16,13 @@ namespace q17 {
#if !defined(Q_OS_VXWORKS)
using std::uninitialized_value_construct;
#else
namespace _detail {
template <typename T>
void *voidify(T &t) {
// LWG3870 changed this for C++23, but this is q_17_, so use the C++17/20 version:
return const_cast<void*>(static_cast<const volatile void*>(std::addressof(t)));
}
} // namespace _detail
// WindRiver confirmed that implementation of `std::uninitialized_value_construct` is not
// working properly in VxWorks 24.03 (probably the same problem appears in older versions) with
// defect VXHVP-9969
@ -26,7 +33,7 @@ namespace q17 {
using ValueType = typename std::iterator_traits<ForwardIt>::value_type;
QT_TRY {
for (; current != last; ++current)
::new (static_cast<void *>(std::addressof(*current))) ValueType();
::new (_detail::voidify(*current)) ValueType();
} QT_CATCH(...) {
std::destroy(first, current);
QT_RETHROW;