QVariant: prepare removal of nullptr_t special casing in Qt 7

customConstruct has to do an additional check to ensure that
QVariant::fromValue(nullptr) returns null.
We can get rid of it by special casing nullptr_t in a fromValue overload
instead, reducing the amount of work that needs to happen at runtime.

Change-Id: I2aea6aecfee0a9404cbd78dbea01a1d5d3047ca0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Fabian Kosmale 2022-07-25 09:37:19 +02:00
parent 2f0a625fd4
commit 708e4ea235
2 changed files with 4 additions and 1 deletions

View File

@ -250,7 +250,8 @@ static void customConstruct(const QtPrivate::QMetaTypeInterface *iface, QVariant
// need to check for nullptr_t here, as this can get called by fromValue(nullptr). fromValue() uses
// std::addressof(value) which in this case returns the address of the nullptr object.
d->is_null = !copy || isInterfaceFor<std::nullptr_t>(iface);
// ### Qt 7: remove nullptr_t special casing
d->is_null = !copy QT6_ONLY(|| isInterfaceFor<std::nullptr_t>(iface));
void *dst;
if (QVariant::Private::canUseInternalSpace(iface)) {

View File

@ -435,6 +435,8 @@ public:
static inline QVariant fromValue(const T &value)
#endif
{
if constexpr (std::is_null_pointer_v<T>)
return QVariant(QMetaType::fromType<std::nullptr_t>());
return QVariant(QMetaType::fromType<T>(), std::addressof(value));
}