Strip cvref from key type in raw_hash_set_base::HashParams::HashKeyFor. In raw_hash_set_base::find_or_prepare_insert_large, Key is FindLargeKey<K>, which is a const reference for keys not passed by value. Stripping cvref in HashParams::HashKeyFor avoids passing reference types to HashKey (which fails to compile under SwisstableGenerationsEnabled when K is an array of unknown bound such as extern const char[], because reference types satisfy is_trivially_move_constructible and trigger sizeof on the incomplete array type in ShouldPreferPassByValueOverRRef) and avoids duplicate HashKey instantiations between small and large table insertion paths. PiperOrigin-RevId: 1021336942
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h index 72bc1ac..a59d09b 100644 --- a/absl/container/internal/raw_hash_set.h +++ b/absl/container/internal/raw_hash_set.h
@@ -2845,7 +2845,7 @@ // other lookup keys first (e.g. `const char*` for `StringHash`). template <class K> using HashKeyFor = - HashKey<Hash, K, kIsAbsl, kSeedShift, + HashKey<Hash, absl::remove_cvref_t<K>, kIsAbsl, kSeedShift, /*kUseCanonical=*/kIsAbsl && std::is_same_v<absl::remove_cvref_t<K>, absl::remove_cvref_t<SlotKey>>>; @@ -2987,8 +2987,7 @@ constexpr static bool kIsAbslHash = HashParams::kIsAbsl; constexpr static size_t kSeedShift = HashParams::kSeedShift; template <class K> - using HashKeyFor = - typename HashParams::template HashKeyFor<absl::remove_cvref_t<K>>; + using HashKeyFor = typename HashParams::template HashKeyFor<K>; constexpr static bool SooEnabled() { return FitsInSooSlot(sizeof(slot_type), alignof(slot_type));
diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc index 62f46c2..9c6ade1 100644 --- a/absl/container/internal/raw_hash_set_test.cc +++ b/absl/container/internal/raw_hash_set_test.cc
@@ -2876,17 +2876,20 @@ } } +extern const char kLazyEmplaceKey[]; + TEST(Table, LazyEmplace) { StringTable t; bool called = false; - auto it = t.lazy_emplace("abc", [&](const StringTable::constructor& f) { - called = true; - f("abc", "ABC"); - }); + auto it = + t.lazy_emplace(kLazyEmplaceKey, [&](const StringTable::constructor& f) { + called = true; + f("abc", "ABC"); + }); EXPECT_TRUE(called); EXPECT_THAT(*it, Pair("abc", "ABC")); called = false; - it = t.lazy_emplace("abc", [&](const StringTable::constructor& f) { + it = t.lazy_emplace(kLazyEmplaceKey, [&](const StringTable::constructor& f) { called = true; f("abc", "DEF"); }); @@ -2894,6 +2897,8 @@ EXPECT_THAT(*it, Pair("abc", "ABC")); } +constexpr char kLazyEmplaceKey[] = "abc"; + int decompose_constructed; int decompose_copy_constructed; int decompose_copy_assigned;