From e5acaa12e3cb3f9eb41657eee8146d82fe436093 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 15 Feb 2020 20:23:40 +0100 Subject: QObject: treat T* -> bool conversions as narrowing Following wg21.link/LWG3228, it was found that a proper variant fix requires that T* -> bool conversions be treated as narrowing conversions in subclause wg21.link/dcl.init.lst. wg21.link/P1957R2 was accepted in Prague 2020 as a DR and retroactively applies to older C++ standards. Since we hard-code the algorithm of [dcl.init.lst], we can and must add this manually. [ChangeLog][QtCore][QObject] For the purposes of QT_NO_NARROWING_CONVERSIONS_IN_CONNECT, pointer (incl. pointer-to-member) to bool conversions are now considered narrowing. This matches the resolution of a defect report in C++ itself. Change-Id: Ifa9a3724c9c8ccd3dd6614928dbbe37477591dc1 Reviewed-by: Ville Voutilainen --- src/corelib/kernel/qobjectdefs_impl.h | 4 ++++ tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/corelib/kernel/qobjectdefs_impl.h b/src/corelib/kernel/qobjectdefs_impl.h index 31ecc8b20d..aed50d6c5a 100644 --- a/src/corelib/kernel/qobjectdefs_impl.h +++ b/src/corelib/kernel/qobjectdefs_impl.h @@ -285,11 +285,15 @@ namespace QtPrivate { { }; + template + using is_bool = std::is_same::type>; + template struct AreArgumentsNarrowedBase::type> : std::integral_constant::value && std::is_integral::value) || (std::is_floating_point::value && std::is_floating_point::value && sizeof(From) > sizeof(To)) || + ((std::is_pointer::value || std::is_member_pointer::value) && QtPrivate::is_bool::value) || ((std::is_integral::value || std::is_enum::value) && std::is_floating_point::value) || (std::is_integral::value && std::is_integral::value && (sizeof(From) > sizeof(To) diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 21615d6ec4..63d06497ce 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -7462,6 +7462,12 @@ void tst_QObject::checkArgumentsForNarrowing() FITS(bool, const QObject *&); FITS(int (*)(bool), void (QObject::*)()); + { + // wg21.link/P1957 + NARROWS(char*, bool); + NARROWS(void (QObject::*)(), bool); + } + #undef IS_UNSCOPED_ENUM_SIGNED #undef NARROWS_IF -- cgit v1.2.3