![]() This adds a static assertion to std::allocator_traits::rebind_alloc to diagnose violations of the rule that rebinding an allocator to its own value type yields the same allocator type. This helps to catch the easy mistake of deriving from std::allocator but forgetting to override the rebind behaviour (no longer an issue in C++20 as std::allocator doesn't have a rebind member that can be inherited). It also catches bugs like in 23_containers/vector/52591.cc where a typo means the rebound allocator is a completely different type. I initially wanted to put this static assert into the body of allocator_traits: static_assert(is_same<rebind_alloc<value_type>, _Alloc>::value, "rebind_alloc<value_type> must be Alloc"); However, this causes a regression in the test for PR libstdc++/72792. It seems that instantiating std::allocator_traits should be allowed for invalid allocator types as long as you don't try to rebind them. To support that, only assert in the __allocator_traits_base::__rebind class template (in both the primary template and the partial specialization). As a result, the bug in 20_util/scoped_allocator/outermost.cc is not diagnosed, because nothing in that test rebinds the allocator. libstdc++-v3/ChangeLog: * include/bits/alloc_traits.h (__allocator_traits_base::__rebind): Add static assert for rebind requirement. * testsuite/20_util/allocator_traits/members/rebind_alloc.cc: Fix invalid rebind member in test allocator. * testsuite/20_util/allocator_traits/requirements/rebind_neg.cc: New test. * testsuite/20_util/scoped_allocator/outermost.cc: Add rebind to test allocator. * testsuite/23_containers/forward_list/48101_neg.cc: Prune new static assert error. * testsuite/23_containers/unordered_multiset/48101_neg.cc: Likewise. * testsuite/23_containers/unordered_set/48101_neg.cc: Likewise. * testsuite/23_containers/vector/52591.cc: Fix typo in rebind. |
||
---|---|---|
.. | ||
backward | ||
bits | ||
c | ||
c_compatibility | ||
c_global | ||
c_std | ||
debug | ||
decimal | ||
experimental | ||
ext | ||
parallel | ||
precompiled | ||
pstl | ||
std | ||
tr1 | ||
tr2 | ||
Makefile.am | ||
Makefile.in |