diff --git a/src/corelib/global/qcomparehelpers.h b/src/corelib/global/qcomparehelpers.h index fce751be09f..2da7fbd8254 100644 --- a/src/corelib/global/qcomparehelpers.h +++ b/src/corelib/global/qcomparehelpers.h @@ -648,6 +648,9 @@ class totally_ordered_wrapper P ptr; public: totally_ordered_wrapper() noexcept = default; + Q_IMPLICIT constexpr totally_ordered_wrapper(std::nullptr_t) + // requires std::is_pointer_v

+ : totally_ordered_wrapper(P{nullptr}) {} explicit constexpr totally_ordered_wrapper(P p) noexcept : ptr(p) {} constexpr P get() const noexcept { return ptr; } diff --git a/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.h b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.h index 16398b0978a..837170d2381 100644 --- a/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.h +++ b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.h @@ -58,6 +58,8 @@ private Q_SLOTS: // Add new test cases to tst_qcomparehelpers1.cpp, because minGW already // complains about a too large tst_qcomparehelpers.cpp.obj object file void compareWithAttributes(); + + void totallyOrderedWrapperBasics(); }; #endif // TST_QCOMPAREHELPERS_H diff --git a/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers1.cpp b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers1.cpp index 16b2842de27..33967f314c4 100644 --- a/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers1.cpp +++ b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers1.cpp @@ -54,3 +54,10 @@ void tst_QCompareHelpers::compareWithAttributes() #undef COMPARE } + +void tst_QCompareHelpers::totallyOrderedWrapperBasics() +{ + Qt::totally_ordered_wrapper pi; // partially-formed + pi = nullptr; + QCOMPARE_EQ(pi.get(), nullptr); +}