qxp::is_detected: add an autotest

It was lacking one.

It seems that all compilers have trouble at checking accessibility in
SFINAE contexts (with various degrees of incompatibilities), therefore
I'm disabling all the tests that try checking for accessibility.

Change-Id: I1456acd3c40f802367a27610b0374f0806e403f5
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Giuseppe D'Angelo 2025-02-01 11:30:11 +01:00
parent 7df128675a
commit 7d22a9c75a
3 changed files with 104 additions and 0 deletions

View File

@ -1,4 +1,5 @@
# Copyright (C) 2024 The Qt Company Ltd. # Copyright (C) 2024 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(function_ref) add_subdirectory(function_ref)
add_subdirectory(is_detected)
add_subdirectory(is_virtual_base_of) add_subdirectory(is_virtual_base_of)

View File

@ -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
)

View File

@ -0,0 +1,86 @@
// Copyright (C) 2025 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/qxptype_traits.h>
#include <QTest>
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 <typename T>
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<HasInnerFooTypedefTest, A>);
static_assert( qxp::is_detected_v<HasInnerFooTypedefTest, B>);
// static_assert(!qxp::is_detected_v<HasInnerFooTypedefTest, C>); // see above
static_assert(!qxp::is_detected_v<HasInnerFooTypedefTest, D>);
static_assert(!qxp::is_detected_v<HasInnerFooTypedefTest, E>);
static_assert(!qxp::is_detected_v<HasInnerFooTypedefTest, F>);
} // InnerTypedefTest
namespace ReflectionTest {
template <typename T>
using HasPublicConstFooFunctionTest = decltype(std::declval<const T &>().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<HasPublicConstFooFunctionTest, A>);
static_assert(!qxp::is_detected_v<HasPublicConstFooFunctionTest, B>);
static_assert( qxp::is_detected_v<HasPublicConstFooFunctionTest, C>);
static_assert(!qxp::is_detected_v<HasPublicConstFooFunctionTest, D>);
static_assert( qxp::is_detected_v<HasPublicConstFooFunctionTest, E>);
static_assert(!qxp::is_detected_v<HasPublicConstFooFunctionTest, F>);
static_assert(!qxp::is_detected_v<HasPublicConstFooFunctionTest, G>);
// static_assert(!qxp::is_detected_v<HasPublicConstFooFunctionTest, H>); // see above
// static_assert(!qxp::is_detected_v<HasPublicConstFooFunctionTest, I>); // see above
} // ReflectionTest
namespace InnerTypedefTestFriend
{
struct Helper
{
template <typename T>
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<Helper::HasInnerFooTypedefTest, A>);
static_assert( qxp::is_detected_v<Helper::HasInnerFooTypedefTest, B>);
// static_assert(!qxp::is_detected_v<Helper::HasInnerFooTypedefTest, C>); // see above
// static_assert(!qxp::is_detected_v<Helper::HasInnerFooTypedefTest, D>); // see above
}
QTEST_APPLESS_MAIN(tst_qxp_is_detected);
#include "tst_is_detected.moc"