From 0943ad02419f6215915e4a7c98949d1fd9b08c45 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 23 Nov 2020 09:08:10 +0100 Subject: Containers: call constructors even for primitive types Trivial types are automatically classified as Q_PRIMITIVE_TYPE, but it doesn't mean that they can be initialized with memset(0) (notably, pointers to data members on Itanium ABIs are initialized with -1, not 0). Drop that kind of optimization, and always value-initialize objects in containers. Fix the documentation to match as well. This is a rework of f6f68409a40beaa5f034c411dd7e296c7828d8fd and 82b13880b994ff9b87710e0729e32035ab3b63a4 in Qt 6. [ChangeLog][QtCore][QTypeInfo] The semantics of Q_PRIMITIVE_TYPE have been slightly changed. Qt now value-initializes types marked as primitive (which, by default, include trivial types) instead of simply using memset(0), which is wrong in some corner cases. Change-Id: Ib61396be883424e2f03a9f3bbce1eaddce6aa731 Reviewed-by: Volker Hilsheimer Reviewed-by: Lars Knoll (cherry picked from commit 76671a57b5418ec98fe2c94a963728ac3306dc82) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/global/qglobal.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/corelib/global') diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 51b8379b3d..12d76c0dca 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -4030,10 +4030,8 @@ bool qunsetenv(const char *varName) \list \li \c Q_PRIMITIVE_TYPE specifies that \a Type is a POD (plain old - data) type with no constructor or destructor, or else a type where - every bit pattern is a valid object; memset()ting memory to zero - creates a value-initialized instance of the type; and memcpy()ing - creates a valid independent copy of an object. + data) type with no constructor or destructor, and for which memcpy()ing + creates a valid independent copy of the object. \li \c Q_MOVABLE_TYPE specifies that \a Type has a constructor and/or a destructor but can be moved in memory using \c memcpy(). Note: despite the name, this has nothing to do with move -- cgit v1.2.3