From c05982fda39bbfa9fa3641c7e5938f204a8b1bf5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 18 Jan 2025 10:37:31 +0100 Subject: [PATCH] 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. Pick-to: 6.9 Change-Id: Ie11589cbc96b8c3c36deaa6101a897f527d92a46 Reviewed-by: Thiago Macieira --- src/corelib/global/q17memory.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/corelib/global/q17memory.h b/src/corelib/global/q17memory.h index aef26b8f382..ae1c55272fd 100644 --- a/src/corelib/global/q17memory.h +++ b/src/corelib/global/q17memory.h @@ -16,6 +16,13 @@ namespace q17 { #if !defined(Q_OS_VXWORKS) using std::uninitialized_value_construct; #else + namespace _detail { + template + 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(static_cast(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::value_type; QT_TRY { for (; current != last; ++current) - ::new (static_cast(std::addressof(*current))) ValueType(); + ::new (_detail::voidify(*current)) ValueType(); } QT_CATCH(...) { std::destroy(first, current); QT_RETHROW;