From 67ed712235375fa1d1b9ea0e5c71755886f65f83 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 2 Feb 2023 07:40:08 +0100 Subject: [PATCH] q20::construct_at(): fix various issues Fix several issues in 72c2cdbc572f8b8b45a57a451e2bc19bb1c53b0c, which I was too slow to review before it went in: - use the correct feature macro, not __cplusplus - use the correct signature (return T*, not void) - don't make the function static - add a comment mentioning the material difference to std::construct_at - drop unneeded include Pick-to: 6.5 Task-number: QTBUG-109394 Change-Id: I39d1908f565b1c1a31d5741924ac173447ec9057 Reviewed-by: Thiago Macieira --- src/corelib/global/q20memory.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/corelib/global/q20memory.h b/src/corelib/global/q20memory.h index 438613db48..bb337a9f7f 100644 --- a/src/corelib/global/q20memory.h +++ b/src/corelib/global/q20memory.h @@ -4,9 +4,12 @@ #ifndef Q20MEMORY_H #define Q20MEMORY_H -#include +#include #include +#include + +#include // // W A R N I N G @@ -26,19 +29,20 @@ QT_BEGIN_NAMESPACE +// like std::construct_at (but not whitelisted for constexpr) namespace q20 { - -#if __cplusplus >= 202002L +#ifdef __cpp_lib_constexpr_dynamic_alloc using std::construct_at; #else template ()) T(std::declval()...))> > - static void construct_at(T *ptr, Args && ... args) +T *construct_at(T *ptr, Args && ... args) { - ::new (const_cast(static_cast(ptr))) T(std::forward(args)...); + return ::new (const_cast(static_cast(ptr))) + T(std::forward(args)...); } -#endif +#endif // __cpp_lib_constexpr_dynamic_alloc } // namespace q20 QT_END_NAMESPACE