qt5base-lts/tests/auto/corelib
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
..
animation Port from container::count() and length() to size() - V5 2022-11-03 14:59:24 +01:00
global tst_qlogging: Skip backtrace tests under ASan 2022-12-21 23:22:59 -03:00
io Add QFileInfo::readSymLink() to read the raw link path 2022-12-23 06:26:44 +01:00
itemmodels Port from container::count() and length() to size() - V5 2022-11-03 14:59:24 +01:00
kernel QMetaType: fix value-initialization in a corner case 2022-12-30 01:51:08 +01:00
mimetypes Port from container::count() and length() to size() - V5 2022-11-03 14:59:24 +01:00
platform CMake: Remove direct qt_android_generate_deployment_settings call 2022-12-15 20:23:28 +01:00
plugin QUuid: add the ability to specify the byte order for 128-bit IDs 2022-12-16 19:29:10 +01:00
serialization QXmlStreamWriter: fix a thinko in doWriteToDevice(QSV) 2022-12-16 22:58:11 +01:00
text tst_QStringApiSymmetry: fix a typo and deal with the fallout 2022-12-29 12:20:27 +01:00
thread tests: fix build with -no-feature-concurrent 2022-11-09 20:33:49 +01:00
time Deprecate QDateTime methods using plain Qt::TimeSpec 2022-12-10 06:39:33 +01:00
tools QOffsetStringArray: add contains() method 2022-12-09 06:22:06 +00:00
CMakeLists.txt Change the license of all CMakeLists.txt and *.cmake files to BSD 2022-08-23 23:58:42 +02:00