tst_QGlobal: add a check for Q_DECLARE_SHARED
Check that it marks types are Q_RELOCATABLE_TYPE and adds the ADL swap(). Pick-to: 6.7 6.5 Change-Id: Ibde0f4ad594e4a6b3636357da2fd211507293b60 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit 91a96ea8fb100fca08b37eb3ba644083b3316e6d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
9ef785082a
commit
072316ccc4
@ -14,7 +14,37 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <type_traits>
|
#include <QtCore/qxptype_traits.h>
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using AdlSwappableTest = decltype(swap(std::declval<T&>(), std::declval<T&>()));
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr bool q_is_adl_swappable_v = qxp::is_detected_v<AdlSwappableTest, T>;
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Q_DECLARE_SHARED
|
||||||
|
//
|
||||||
|
#define MAKE_CLASS(C) \
|
||||||
|
struct C \
|
||||||
|
{ \
|
||||||
|
std::string s; \
|
||||||
|
explicit C(std::string s = {}) : s{std::move(s)} {} \
|
||||||
|
void swap(C &other) noexcept { std::swap(s, other.s); } \
|
||||||
|
} \
|
||||||
|
/* end */
|
||||||
|
|
||||||
|
MAKE_CLASS(NotQDeclareShared);
|
||||||
|
static_assert(!q_is_adl_swappable_v<NotQDeclareShared>);
|
||||||
|
|
||||||
|
MAKE_CLASS(Terry); // R.I.P.
|
||||||
|
Q_DECLARE_SHARED(Terry)
|
||||||
|
|
||||||
|
#undef MAKE_CLASS
|
||||||
|
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
class tst_QGlobal: public QObject
|
class tst_QGlobal: public QObject
|
||||||
{
|
{
|
||||||
@ -31,6 +61,8 @@ private slots:
|
|||||||
void qConstructorFunction();
|
void qConstructorFunction();
|
||||||
void qCoreAppStartupFunction();
|
void qCoreAppStartupFunction();
|
||||||
void qCoreAppStartupFunctionRestart();
|
void qCoreAppStartupFunctionRestart();
|
||||||
|
void qDeclareSharedMarksTheTypeRelocatable();
|
||||||
|
void qDeclareSharedMakesTheTypeAdlSwappable();
|
||||||
void integerForSize();
|
void integerForSize();
|
||||||
void int128Literals();
|
void int128Literals();
|
||||||
void buildAbiEndianness();
|
void buildAbiEndianness();
|
||||||
@ -395,6 +427,32 @@ void tst_QGlobal::qCoreAppStartupFunctionRestart()
|
|||||||
qCoreAppStartupFunction();
|
qCoreAppStartupFunction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QGlobal::qDeclareSharedMarksTheTypeRelocatable()
|
||||||
|
{
|
||||||
|
static_assert(!QTypeInfo<QT_PREPEND_NAMESPACE(NotQDeclareShared)>::isRelocatable);
|
||||||
|
static_assert( QTypeInfo<QT_PREPEND_NAMESPACE(Terry)>::isRelocatable);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QGlobal::qDeclareSharedMakesTheTypeAdlSwappable()
|
||||||
|
{
|
||||||
|
static_assert(!q_is_adl_swappable_v<QT_PREPEND_NAMESPACE(NotQDeclareShared)>);
|
||||||
|
static_assert( q_is_adl_swappable_v<QT_PREPEND_NAMESPACE(Terry)>);
|
||||||
|
|
||||||
|
#define CHECK(Class) do { \
|
||||||
|
using C = QT_PREPEND_NAMESPACE(Class); \
|
||||||
|
C lhs("lhs"); \
|
||||||
|
C rhs("rhs"); \
|
||||||
|
QCOMPARE_EQ(lhs.s, "lhs"); \
|
||||||
|
QCOMPARE_EQ(rhs.s, "rhs"); \
|
||||||
|
/* no using std::swap - we're checking whether the ADL swap works */ \
|
||||||
|
swap(lhs, rhs); \
|
||||||
|
QCOMPARE_EQ(lhs.s, "rhs"); \
|
||||||
|
QCOMPARE_EQ(rhs.s, "lhs"); \
|
||||||
|
} while (false)
|
||||||
|
CHECK(Terry);
|
||||||
|
#undef CHECK
|
||||||
|
}
|
||||||
|
|
||||||
struct isEnum_A {
|
struct isEnum_A {
|
||||||
int n_;
|
int n_;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user