[Development] QMetaType::NeedsConstruction vs QTypeInfo<T>::isComplex

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Mon Mar 1 12:16:24 CET 2021

On 01/03/2021 11:45, Fabian Kosmale wrote:
> currently we promise that if for a type its QMetaType does not have the NeedsConstruction flag set, it can be initialized with memzero. We set that flag if the type is complex according to QTypeInfo. However, after the discussion inhttps://lists.qt-project.org/pipermail/development/2020-November/040546.html, primitive types are not complex, but only guarantee that they can be memcpyed not memzeroed. Therefore either the implementation or the documentation of NeedsConstruction needs  to change (note that Qt itself does not use that flag anywhere as far as I can tell).
> But which of those two options should we choose? What are the actual use-cases of that flag anyway?

Well, one of the outcomes of that discussion is that we can't at the 
same time

- assume that trivial types are PRIMITIVE, and
- zero-initialize PRIMITIVE types

because of things like pointers to data members. So we've decided to 
ditch zero-initialization and go for value-initializing everything, 
pushing the "problem" of replacing a loop of value-initializations with 
a corresponding memset(0).

I guess that the NeedsConstruction flag has not been updated; FWIW, it 
could be ditched entirely? All types are value initialized, whether it's 
in containers, in QVariants and so on.

Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4329 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.qt-project.org/pipermail/development/attachments/20210301/9b965902/attachment.bin>

More information about the Development mailing list