[Development] What's Q_PRIMITIVE_TYPE for?

Andrei Golubev andrei.golubev at qt.io
Wed Nov 11 12:32:57 CET 2020


I'd stay away from classification using std:: type traits, as we want
something that cannot automatically be inferred from compilers:
in the general case, a compiler cannot know that default construction =
memset to 0 (e.g. out of line constructor); and certainly they cannot
know about relocatability.
Yeah, my example is the minimal one to show what happens by default if you don't have any Q_DECLARE_TYPEINFO (in which case we can still detect certain things as candidates for primitive or relocatable albeit might be dangerous, true)

(This gives us some leeway to stop detecting isComplex in destruction
paths, and just go with std::destroy unconditionally, simplifying our code.)
Oh, I didn't think of that, this sounds nice to have.

Just to insist on this: there are no guarantees coming from the Standard
that null pointers are all 0 bits. The only guarantees, if any, come
from our platforms / platforms' ABI.
Please excuse my poor example, yet the point of primitive vs relocatable shown in it still holds for e.g. Primitive { int i; } vs NotPrimitive { int i = 0; }. In which case you likely would want to have a Q_DECLARE_TYPEINFO(NotPrimitive, Q_PRIMITIVE_TYPE) and this is the only way to get to QPodArrayOps for such cases (which reinforces the usefulness of the macro being discussed).

So, one has to be extremely careful with marking something as primitive,
and I don't think we have any tests regarding this (but we don't run on
any platform with "fancy" null pointers either, I guess).

I am actually unsure whether we have anything, that contains a pointer, marked as primitive.
Also, QString should be relocatable, but complex AFAIR.

--
Best Regards,
Andrei
________________________________
From: Development <development-bounces at qt-project.org> on behalf of Giuseppe D'Angelo via Development <development at qt-project.org>
Sent: Wednesday, November 11, 2020 12:04 PM
To: development at qt-project.org <development at qt-project.org>
Subject: Re: [Development] What's Q_PRIMITIVE_TYPE for?

Il 10/11/20 20:00, Giuseppe D'Angelo via Development ha scritto:
> Yes, sure. But also something like QStringView, which is (char16_t*,
> qsizetype), is a primitive type (assuming all-0 representation for a
> null pointer).

Just to insist on this: there are no guarantees coming from the Standard
that null pointers are all 0 bits. The only guarantees, if any, come
from our platforms / platforms' ABI.

For instance , on the Itanium ABI:

* struct A { int a, b; }; can be value-initialized with 0 bits
* struct B { int *ptr; }; can be value-initialized with 0 bits
* struct C { int A::* ptr; }; *CANNOT BE VALUE-INITIALIZED* with 0 bits.

Because null pointers to data members are initialized with the value
"-1". https://gcc.godbolt.org/z/3aWWYx

So, one has to be extremely careful with marking something as primitive,
and I don't think we have any tests regarding this (but we don't run on
any platform with "fancy" null pointers either, I guess).


Thanks,
--
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 --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20201111/9bf9a8d8/attachment.html>


More information about the Development mailing list