From 24e57ce6caade9161912515b58072c9a095c2cd6 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 28 Sep 2023 09:10:25 +0200 Subject: [PATCH] QTestPrivate property tests: don't try to create abstract types Amends 5743837a26fce1962c0480bc7536b4c2d0e69997, after which Qt Positioning and Qt SCXML failed to build as some properties operate on abstract classes. Check whether we can instantiate the tested class before trying to do so, otherwise return a default-constructed unique_ptr. Pick-to: 6.5 Change-Id: Ida9d4375197a93438062b1e1473b4a2a22cc7054 Reviewed-by: Ulf Hermann (cherry picked from commit f791570b86ce4a0da45bb6e617701a48ee8189b7) Reviewed-by: Qt Cherry-pick Bot --- src/testlib/qpropertytesthelper_p.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/testlib/qpropertytesthelper_p.h b/src/testlib/qpropertytesthelper_p.h index b4fc0fb7694..06d503f8756 100644 --- a/src/testlib/qpropertytesthelper_p.h +++ b/src/testlib/qpropertytesthelper_p.h @@ -108,7 +108,12 @@ void testReadWritePropertyBasics( std::function represent = [](const PropertyType &val) { return QTest::toString(val); }, std::function(void)> helperConstructor = - []() { return std::make_unique(); }) + []() { + if constexpr (std::is_default_constructible_v) + return std::make_unique(); + else + return std::unique_ptr(); + }) { // get the property const QMetaObject *metaObject = instance.metaObject(); @@ -281,7 +286,12 @@ void testWriteOncePropertyBasics( std::function represent = [](const PropertyType &val) { return QTest::toString(val); }, std::function(void)> helperConstructor = - []() { return std::make_unique(); }) + []() { + if constexpr (std::is_default_constructible_v) + return std::make_unique(); + else + return std::unique_ptr(); + }) { Q_UNUSED(helperConstructor);