From 7d8150da4c20e1f9165e3c2642a183446220dd04 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 21 Mar 2022 20:38:07 +0100 Subject: [PATCH] QVariant: disable building from arbitrary pointers The QVariant(bool) is an extremely dangerous catch-all for all sorts of things that may convert to bool, including arbitrary pointers. Delete the corresponding constructor, in order to force users to use the (correct) construction using fromValue, and/or to prevent bugs altogether. This is technically speaking a SiC, but one of type A -- if pointer to bool was intented, just do the conversion explicitly. [ChangeLog][QtCore][QVariant] QVariant used to be constructible by raw pointers through a conversion towards bool. This is now illegal. If such a conversion is needed, users are advised to insert manual casts to bool. Change-Id: I1b1f81962259514e57d841246740e0f7050104e0 Reviewed-by: Thiago Macieira --- src/corelib/kernel/qvariant.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index ffc091ebf9..3481a5e347 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -228,6 +228,14 @@ class Q_CORE_EXPORT QVariant QVariant(const QModelIndex &modelIndex); QVariant(const QPersistentModelIndex &modelIndex); #endif +#if !defined(Q_CC_GHS) + // GHS has an ICE with this code; use the simplified version below + template , std::is_member_pointer>, bool> = false> + QVariant(T) = delete; +#else + QVariant(const volatile void *) = delete; +#endif QVariant& operator=(const QVariant &other); inline QVariant(QVariant &&other) noexcept : d(other.d)