Fix GCC 6 warning about placement-new operator on too little space
GCC 6 is able to detect when you use a placement new of an object in a space that is too small to contain it. qvariant_p.h: In instantiation of ‘void v_construct(QVariant::Private*, const T&) [with T = QRectF]’: qvariant_p.h:142:9: error: placement new constructing an object of type ‘QRectF’ and size ‘32’ in a region of type ‘void*’ and size ‘8’ [-Werror=placement-new] new (&x->data.ptr) T(t); ^~~~~~~~~~~~~~~~~~~~~~~ This happens even for the false branch of a constant expression (the enum). So split the v_construct function in two pairs, one pair for being able to use the internal space and one pair not so. Change-Id: Ibc83b9f7e3bc4962ae35ffff1425ed898f279dea Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
This commit is contained in:
parent
9f09fed72f
commit
70092c9a47
@ -60,6 +60,7 @@ struct QVariantIntegrator
|
|||||||
{
|
{
|
||||||
static const bool CanUseInternalSpace = sizeof(T) <= sizeof(QVariant::Private::Data)
|
static const bool CanUseInternalSpace = sizeof(T) <= sizeof(QVariant::Private::Data)
|
||||||
&& ((QTypeInfoQuery<T>::isRelocatable) || Q_IS_ENUM(T));
|
&& ((QTypeInfoQuery<T>::isRelocatable) || Q_IS_ENUM(T));
|
||||||
|
typedef QtPrivate::integral_constant<bool, CanUseInternalSpace> CanUseInternalSpace_t;
|
||||||
};
|
};
|
||||||
Q_STATIC_ASSERT(QVariantIntegrator<double>::CanUseInternalSpace);
|
Q_STATIC_ASSERT(QVariantIntegrator<double>::CanUseInternalSpace);
|
||||||
Q_STATIC_ASSERT(QVariantIntegrator<long int>::CanUseInternalSpace);
|
Q_STATIC_ASSERT(QVariantIntegrator<long int>::CanUseInternalSpace);
|
||||||
@ -110,31 +111,49 @@ private:
|
|||||||
T m_t;
|
T m_t;
|
||||||
};
|
};
|
||||||
|
|
||||||
// constructs a new variant if copy is 0, otherwise copy-constructs
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline void v_construct(QVariant::Private *x, const void *copy, T * = 0)
|
inline void v_construct_helper(QVariant::Private *x, const T &t, QtPrivate::true_type)
|
||||||
{
|
{
|
||||||
if (!QVariantIntegrator<T>::CanUseInternalSpace) {
|
new (&x->data) T(t);
|
||||||
x->data.shared = copy ? new QVariantPrivateSharedEx<T>(*static_cast<const T *>(copy))
|
x->is_shared = false;
|
||||||
: new QVariantPrivateSharedEx<T>;
|
}
|
||||||
} else {
|
|
||||||
if (copy)
|
template <class T>
|
||||||
new (&x->data.ptr) T(*static_cast<const T *>(copy));
|
inline void v_construct_helper(QVariant::Private *x, const T &t, QtPrivate::false_type)
|
||||||
else
|
{
|
||||||
new (&x->data.ptr) T();
|
x->data.shared = new QVariantPrivateSharedEx<T>(t);
|
||||||
}
|
x->is_shared = true;
|
||||||
x->is_shared = !QVariantIntegrator<T>::CanUseInternalSpace;
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline void v_construct_helper(QVariant::Private *x, QtPrivate::true_type)
|
||||||
|
{
|
||||||
|
new (&x->data) T();
|
||||||
|
x->is_shared = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline void v_construct_helper(QVariant::Private *x, QtPrivate::false_type)
|
||||||
|
{
|
||||||
|
x->data.shared = new QVariantPrivateSharedEx<T>;
|
||||||
|
x->is_shared = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline void v_construct(QVariant::Private *x, const T &t)
|
inline void v_construct(QVariant::Private *x, const T &t)
|
||||||
{
|
{
|
||||||
if (!QVariantIntegrator<T>::CanUseInternalSpace) {
|
// dispatch
|
||||||
x->data.shared = new QVariantPrivateSharedEx<T>(t);
|
v_construct_helper(x, t, typename QVariantIntegrator<T>::CanUseInternalSpace_t());
|
||||||
} else {
|
}
|
||||||
new (&x->data.ptr) T(t);
|
|
||||||
}
|
// constructs a new variant if copy is 0, otherwise copy-constructs
|
||||||
x->is_shared = !QVariantIntegrator<T>::CanUseInternalSpace;
|
template <class T>
|
||||||
|
inline void v_construct(QVariant::Private *x, const void *copy, T * = 0)
|
||||||
|
{
|
||||||
|
if (copy)
|
||||||
|
v_construct<T>(x, *static_cast<const T *>(copy));
|
||||||
|
else
|
||||||
|
v_construct_helper<T>(x, typename QVariantIntegrator<T>::CanUseInternalSpace_t());
|
||||||
}
|
}
|
||||||
|
|
||||||
// deletes the internal structures
|
// deletes the internal structures
|
||||||
|
Loading…
Reference in New Issue
Block a user