diff options
| author | Marc Mutz <[email protected]> | 2025-11-17 10:37:57 +0100 |
|---|---|---|
| committer | Marc Mutz <[email protected]> | 2025-11-21 06:58:04 +0000 |
| commit | 76ea1a5730e160cf52723003c8de43f7f9a21388 (patch) | |
| tree | bdb1881ecded77bed4ae4cdb07377f194ab58a71 | |
| parent | 83b53994476d19a570c4e22f041a66564374fb35 (diff) | |
Make QHashDummyValue more robust
As is customary for tag structs, make the default ctor explicit to
avoid construction as '{}'.
Make op== constexpr (drive-by: make it a hidden friend instead of a
member function), and add op!= to C++17 builds, for symmetry.
=delete the qHash() overload so it doesn't accidentally match
some other overload.
We should eventually also =delete equality, but atm, this breaks
QSet::compareEquals, which calls QHash::op==, which (incorrectly)
SFINAE's out for a non-equality-comparable QHashDummyValue
mapped_type.
Amends 5b7c3e31b538376f2b4733bd868b5875b504cdb3.
Not picking back, as it's a rather isolated change with very little
chance of creating conflicts going forward, but non-negligible chance
of breaking something in older branches.
Change-Id: I8125581c476f854ebe4f9ddc791d3ddce9f169d0
Reviewed-by: Thiago Macieira <[email protected]>
| -rw-r--r-- | src/corelib/tools/qhash.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 76729917f6b..6509048da0c 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -23,7 +23,13 @@ QT_BEGIN_NAMESPACE struct QHashDummyValue { - bool operator==(const QHashDummyValue &) const noexcept { return true; } + explicit QHashDummyValue() = default; + friend constexpr bool operator==(QHashDummyValue, QHashDummyValue) noexcept { return true; } +#ifndef __cpp_impl_three_way_comparison + friend constexpr bool operator!=(QHashDummyValue, QHashDummyValue) noexcept { return false; } +#endif + friend constexpr size_t qHash(QHashDummyValue) noexcept = delete; + friend constexpr size_t qHash(QHashDummyValue, size_t) noexcept = delete; }; namespace QHashPrivate { |
