diff --git a/tests/auto/corelib/global/qxp/CMakeLists.txt b/tests/auto/corelib/global/qxp/CMakeLists.txt index 8292462d17a..1515d712b56 100644 --- a/tests/auto/corelib/global/qxp/CMakeLists.txt +++ b/tests/auto/corelib/global/qxp/CMakeLists.txt @@ -1,4 +1,5 @@ # Copyright (C) 2024 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause add_subdirectory(function_ref) +add_subdirectory(is_detected) add_subdirectory(is_virtual_base_of) diff --git a/tests/auto/corelib/global/qxp/is_detected/CMakeLists.txt b/tests/auto/corelib/global/qxp/is_detected/CMakeLists.txt new file mode 100644 index 00000000000..6b700af2b9f --- /dev/null +++ b/tests/auto/corelib/global/qxp/is_detected/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qxp_is_detected LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qxp_is_detected + EXCEPTIONS + SOURCES + tst_is_detected.cpp + LIBRARIES + Qt::Core +) + diff --git a/tests/auto/corelib/global/qxp/is_detected/tst_is_detected.cpp b/tests/auto/corelib/global/qxp/is_detected/tst_is_detected.cpp new file mode 100644 index 00000000000..16170dab358 --- /dev/null +++ b/tests/auto/corelib/global/qxp/is_detected/tst_is_detected.cpp @@ -0,0 +1,86 @@ +// Copyright (C) 2025 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include + +#include + +class tst_qxp_is_detected : public QObject +{ + Q_OBJECT +}; + +// ALl major compilers have bugs regarding handling accessibility +// from SFINAE contexts; skip tests relying on it. + +namespace InnerTypedefTest { + +template +using HasInnerFooTypedefTest = typename T::Foo; + +struct A {}; +struct B { using Foo = void; }; +class C { using Foo = void; }; // inaccessible +struct D { int Foo; }; +struct E { int Foo() const; }; +struct F { static void Foo(); }; + +static_assert(!qxp::is_detected_v); +static_assert( qxp::is_detected_v); +// static_assert(!qxp::is_detected_v); // see above +static_assert(!qxp::is_detected_v); +static_assert(!qxp::is_detected_v); +static_assert(!qxp::is_detected_v); + +} // InnerTypedefTest + +namespace ReflectionTest { + +template +using HasPublicConstFooFunctionTest = decltype(std::declval().foo()); + +struct A {}; +struct B { void foo(); }; +struct C { void foo() const; }; +struct D { void foo(int) const; }; +struct E { void foo(int = 42) const; }; +struct F { void foo() const &&; }; +struct G { int foo; }; +class H { void foo(); }; +class I { void foo() const; }; + +static_assert(!qxp::is_detected_v); +static_assert(!qxp::is_detected_v); +static_assert( qxp::is_detected_v); +static_assert(!qxp::is_detected_v); +static_assert( qxp::is_detected_v); +static_assert(!qxp::is_detected_v); +static_assert(!qxp::is_detected_v); +// static_assert(!qxp::is_detected_v); // see above +// static_assert(!qxp::is_detected_v); // see above + +} // ReflectionTest + +namespace InnerTypedefTestFriend +{ + +struct Helper +{ + template + using HasInnerFooTypedefTest = typename T::Foo; +}; + +struct A {}; +struct B { using Foo = void; }; +class C { using Foo = void; }; // inaccessible +class D { friend struct Helper; using Foo = void; }; + +static_assert(!qxp::is_detected_v); +static_assert( qxp::is_detected_v); +// static_assert(!qxp::is_detected_v); // see above +// static_assert(!qxp::is_detected_v); // see above +} + +QTEST_APPLESS_MAIN(tst_qxp_is_detected); + +#include "tst_is_detected.moc"