qt5base-lts/tests/auto/corelib/kernel
Giuseppe D'Angelo e8f5f20319 QMetaType: fix value-initialization in a corner case
If a type is trivially default constructible, QMetaType (and QVariant)
think that it can be built and value-initialized by zero-filling a
region of storage and then "blessing" that storage as an actual instance
of the type to build. This is done as an optimization.

This doesn't work for all trivially constructible types. For instance,
on the Itanium C++ ABI, pointers to data members are actually
value-initialized (= zero-initialized, = initialized to null) with the
value -1:

https://itanium-cxx-abi.github.io/cxx-abi/abi.html#data-member-pointers

This means that a type like

  struct A { int A::*ptr; };

is trivially constructible, but its value initialization is not
equivalent to zero-filling its storage.

Since C++ does not offer a type trait we can use for the detection that
we want to do here, and since we have also decided that Q_PRIMITIVE_TYPE
isn't that trait (it just means trivially copyable / destructible), I'm
rolling out a custom type trait for the purpose.

This type trait is private for the moment being (there's no
Q_DECLARE_TYPEINFO for it), and limited to the subset of scalar types
that we know can be value-initialized by memset(0) into their storage
(basically, all of them, except for pointers to data members).

The fix tries to keep the pre-existing semantics of
`QMetaType::NeedsConstruction`. Before, the flag was set for types which
were not trivially default constructible. That included types that
aren't default constructible, or types that cannot do so trivially.
I've left that meaning unchanged, and simply amended the "trivial" part
with the custom trait. A fix there (to clarify the semantics) can be
done as a separate change.

Change-Id: Id8da6acb913df83fc87e5d37e2349a4628e72e91
Pick-to: 6.5
Fixes: QTBUG-109594
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2022-12-30 01:51:08 +01:00
..
qapplicationstatic Change the license of all CMakeLists.txt and *.cmake files to BSD 2022-08-23 23:58:42 +02:00
qcoreapplication Port from container::count() and length() to size() - V5 2022-11-03 14:59:24 +01:00
qdeadlinetimer Remove preprocessor conditionals for chrono include 2022-09-16 08:09:05 +02:00
qelapsedtimer Change the license of all CMakeLists.txt and *.cmake files to BSD 2022-08-23 23:58:42 +02:00
qeventdispatcher Port from container.count()/length() to size() 2022-10-04 07:40:08 +02:00
qeventloop Port from container::count() and length() to size() - V5 2022-11-03 14:59:24 +01:00
qjnienvironment CMake: Remove direct qt_android_generate_deployment_settings call 2022-12-15 20:23:28 +01:00
qjniobject CMake: Remove direct qt_android_generate_deployment_settings call 2022-12-15 20:23:28 +01:00
qjnitypes JNI: add generic support for array-types 2022-10-10 20:19:30 +02:00
qmath Change the license of all CMakeLists.txt and *.cmake files to BSD 2022-08-23 23:58:42 +02:00
qmetacontainer Change the license of all CMakeLists.txt and *.cmake files to BSD 2022-08-23 23:58:42 +02:00
qmetaenum Change the license of all CMakeLists.txt and *.cmake files to BSD 2022-08-23 23:58:42 +02:00
qmetamethod Change the license of all CMakeLists.txt and *.cmake files to BSD 2022-08-23 23:58:42 +02:00
qmetaobject Port from container::count() and length() to size() - V5 2022-11-03 14:59:24 +01:00
qmetaobjectbuilder Port from container::count() and length() to size() - V5 2022-11-03 14:59:24 +01:00
qmetaproperty Change the license of all CMakeLists.txt and *.cmake files to BSD 2022-08-23 23:58:42 +02:00
qmetatype QMetaType: fix value-initialization in a corner case 2022-12-30 01:51:08 +01:00
qmimedata Port from container.count()/length() to size() 2022-10-04 07:40:08 +02:00
qobject Port from container.count()/length() to size() 2022-10-04 07:40:08 +02:00
qpointer Compile guard tests in corelib/kernel that need threading support 2022-09-11 19:36:49 +02:00
qproperty QBindable: Make ordinary Q_PROPERTYs bindable 2022-11-30 21:21:03 +00:00
qsharedmemory Port from container::count() and length() to size() - V5 2022-11-03 14:59:24 +01:00
qsignalblocker Change the license of all CMakeLists.txt and *.cmake files to BSD 2022-08-23 23:58:42 +02:00
qsignalmapper Change the license of all CMakeLists.txt and *.cmake files to BSD 2022-08-23 23:58:42 +02:00
qsocketnotifier Port from container::count() and length() to size() - V5 2022-11-03 14:59:24 +01:00
qsystemsemaphore Port from container::count() and length() to size() - V5 2022-11-03 14:59:24 +01:00
qtimer Port from container::count() and length() to size() - V5 2022-11-03 14:59:24 +01:00
qtranslator Compile guard tests in corelib/kernel that need threading support 2022-09-11 19:36:49 +02:00
qvariant Adapt corelib to use QTimeZone in place of Qt::TimeSpec 2022-12-09 16:16:48 +01:00
qwineventnotifier Change the license of all CMakeLists.txt and *.cmake files to BSD 2022-08-23 23:58:42 +02:00
qwinregistrykey QWinRegistryKey: Fix how we handle the default value, take 2 2022-10-28 09:27:13 +00:00
CMakeLists.txt tests: fix configuring with -no-feature-gui 2022-10-29 01:04:09 +02:00