[Bug libstdc++/115285] [12/13/14/15 Regression] std::unordered_set can have duplicate value

François Dumont frs.dumont@gmail.com
Thu Oct 24 18:43:01 GMT 2024


Committed as trivial the attached patch.

     libstdc++: Fix test broken when using COW std::string

     libstdc++-v3/ChangeLog:

             * testsuite/23_containers/unordered_map/96088.cc (test03): 
Fix increments
             value when _GLIBCXX_USE_CXX11_ABI is equal to 0.

I took the time to fully understand why we need special case for COW 
string. So I'm going to forget what I said below.

I will backport next week.

François


On 24/10/2024 19:33, François Dumont wrote:
> Yes, just got the email about it too.
>
> I'm just going to fix this problem in a simple way for now. But I 
> think I'll consider to replace usages of std::string with an abi 
> agnostic type in the future.
>
> Sorry, François
>
>
> On 24/10/2024 10:09, Jonathan Wakely wrote:
>> I'm seeing new FAILs with -D_GLIBCXX_USE_CXX11_ABI=0
>>
>> /home/test/src/gcc/libstdc++-v3/testsuite/23_containers/unordered_set/96088.cc:247: 
>>
>> void test03(): Assertion '__gnu_test::counter::get()._M_increments ==
>> in
>> crements + 1' failed.
>> FAIL: 23_containers/unordered_set/96088.cc  -std=gnu++17 execution test
>>
>> /home/test/src/gcc/libstdc++-v3/testsuite/23_containers/unordered_map/96088.cc:240: 
>>
>> void test03(): Assertion '__gnu_test::counter::count() == origin +
>> incre
>> ments' failed.
>> FAIL: 23_containers/unordered_map/96088.cc  -std=gnu++17 execution test
>>
>>
>>
>> On Tue, 22 Oct 2024 at 18:28, François Dumont <frs.dumont@gmail.com> 
>> wrote:
>>> Hi
>>>
>>>       libstdc++: Always instantiate key_type to compute hash code 
>>> [PR115285]
>>>
>>>       Even if it is possible to compute a hash code from the inserted
>>> arguments
>>>       we need to instantiate the key_type to guaranty hash code 
>>> consistency.
>>>
>>>       Preserve the lazy instantiation of the mapped_type in the 
>>> context of
>>>       associative containers.
>>>
>>>       libstdc++-v3/ChangeLog:
>>>
>>>               PR libstdc++/115285
>>>               * include/bits/hashtable.h (_S_forward_key<_Kt>): Always
>>> return a temporary
>>>               key_type instance.
>>>               * testsuite/23_containers/unordered_map/96088.cc: 
>>> Adapt to
>>> additional instanciation.
>>>               Also check that mapped_type is not instantiated when 
>>> there
>>> is no insertion.
>>>               * testsuite/23_containers/unordered_multimap/96088.cc:
>>> Adapt to additional
>>>               instanciation.
>>>               * testsuite/23_containers/unordered_multiset/96088.cc:
>>> Likewise.
>>>               * testsuite/23_containers/unordered_set/96088.cc: 
>>> Likewise.
>>>               * testsuite/23_containers/unordered_set/pr115285.cc: New
>>> test case.
>>>
>>>
>>> Tested under Linux x64,
>>>
>>> ok to commit ?
>>>
>>> François
-------------- next part --------------
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/96088.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/96088.cc
index b5be7d06aa0..ee41675a16b 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_map/96088.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_map/96088.cc
@@ -233,9 +233,8 @@ test03()
     um.insert(v.begin(), v.end());
     VERIFY( um.size() == 1 );
 
-    // Allocate array of buckets, a node, the std::string value and the
-    // std::string key (unless COW).
-    constexpr std::size_t increments = _GLIBCXX_USE_CXX11_ABI ? 4 : 3;
+    // Allocate array of buckets, a node, and the 2 std::string (unless COW).
+    constexpr std::size_t increments = _GLIBCXX_USE_CXX11_ABI ? 4 : 2;
 
     VERIFY( __gnu_test::counter::count() == origin + increments );
     VERIFY( __gnu_test::counter::get()._M_increments == increments );


More information about the Libstdc++ mailing list