From 43742adf7bc6a092b59f187fde977a39ebdc70b8 Mon Sep 17 00:00:00 2001 From: Dennis Oberst Date: Tue, 23 May 2023 13:25:54 +0200 Subject: [PATCH] CompareAgainstLiteralZero: fix SFINAE considerations This issue arose during the comparison of two different ordering types. When comparing QPartialOrdering::Less to QStrongOrdering::Less, an unintended overload was considered due to the SFINAE ctor-overload of CompareAgainstLiteralZero. For example: static_assert(QPartialOrdering::Less == QStrongOrdering::Less); would consider: friend constexpr bool operator==(QtPrivate::CompareAgainstLiteralZero, QStrongOrdering rhs) noexcept as an overload. To address this, a stricter approach is now used by triggering the SFINAE-check on std::nullptr_t instead. This resolves the ambiguity while still rejecting std::nullptr_t as intended. As the compiler is unable to resolve this automatically, this refactoring is required. Change-Id: I9ab7e55d2822980198f38f5a66143387999a4d94 Reviewed-by: Giuseppe D'Angelo (cherry picked from commit 1d487e559367e5a71d111fe2c3e13dca0188306c) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/global/qcompare_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/global/qcompare_impl.h b/src/corelib/global/qcompare_impl.h index a2670a2b495..2556f4af6b0 100644 --- a/src/corelib/global/qcompare_impl.h +++ b/src/corelib/global/qcompare_impl.h @@ -22,7 +22,7 @@ public: using SafeZero = void (CompareAgainstLiteralZero::*)(); Q_IMPLICIT constexpr CompareAgainstLiteralZero(SafeZero) noexcept {} - template , bool> = false> + template , bool> = true> CompareAgainstLiteralZero(T) = delete; };