From dd4b0a3ab9e0c49d20c7844be2b7a81e73fd8edb Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 4 Apr 2022 08:40:43 -0700 Subject: [PATCH] QObjectPrivate: use ConnectionList's constructor instead of copy-assignment For all new elements, this is the correct thing to do. This seems to work around an MSVC compiler bug on ARM64. It also seems to generate better code for x86-64 too, as a nice bonus. See: https://developercommunity.visualstudio.com/t/codegen-elides-initializers-when-copying/10004323 Before: https://msvc.godbolt.org/z/Wcd4haaPd After: https://msvc.godbolt.org/z/vWYjazWGr, https://gcc.godbolt.org/z/hdsvTq9nE Fixes: QTBUG-102246 Change-Id: I29f1c141c0f7436393d9fffd16e2bbbf4c0fe54d Reviewed-by: Marc Mutz (cherry picked from commit bc6087fce259fe600c5d12785fa5f293f129965b) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qobject_p.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h index ac77d898da4..c3805107dc9 100644 --- a/src/corelib/kernel/qobject_p.h +++ b/src/corelib/kernel/qobject_p.h @@ -311,11 +311,14 @@ public: SignalVector *newVector = reinterpret_cast(malloc(sizeof(SignalVector) + (size + 1) * sizeof(ConnectionList))); int start = -1; if (vector) { + // not (yet) existing trait: + //static_assert(std::is_relocatable_v); + //static_assert(std::is_relocatable_v); memcpy(newVector, vector, sizeof(SignalVector) + (vector->allocated + 1) * sizeof(ConnectionList)); start = vector->count(); } for (int i = start; i < int(size); ++i) - newVector->at(i) = ConnectionList(); + new (&newVector->at(i)) ConnectionList(); newVector->next = nullptr; newVector->allocated = size;