From 799f6bf43f6724239a90456390d99383099389ce Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 6 Sep 2024 10:38:44 +0200 Subject: [PATCH] Q(Multi)Hash: Fix underconstrained heterogenous operator[] If the key doesn't exist yet in the map, we need to be able to create an actual Key object. Consequently, we require that the type is actually convertible. This doesn't fix any broken code, but avoids compilation errors in QHash internals bubbling up. Note that the existence of a comomn_reference does not imply convertibility (so the concept version wasn't strict enough either). Done-with: Fabian Kosmale Change-Id: I4ed46f343817932063084642093cac193fd9554f Reviewed-by: Thiago Macieira (cherry picked from commit a338f67dceed61009375a4a90a7fe32a06b443a0) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/tools/qhash.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 1c28791d743..1e327b4e5b1 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -1380,6 +1380,9 @@ private: template using if_heterogeneously_seachable = QHashPrivate::if_heterogeneously_seachable_with; + template + using if_key_constructible_from = std::enable_if_t, bool>; + public: template = true> bool remove(const K &key) @@ -1417,7 +1420,7 @@ public: else return defaultValue; } - template = true> + template = true, if_key_constructible_from = true> T &operator[](const K &key) { return operatorIndexImpl(key); @@ -2389,6 +2392,9 @@ private: template using if_heterogeneously_seachable = QHashPrivate::if_heterogeneously_seachable_with; + template + using if_key_constructible_from = std::enable_if_t, bool>; + public: template = true> qsizetype remove(const K &key) @@ -2423,7 +2429,7 @@ public: else return defaultValue; } - template = true> + template = true, if_key_constructible_from = true> T &operator[](const K &key) { return operatorIndexImpl(key);