mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-03-20 13:31:10 +08:00
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.
…
…
…
…
…
…
…
…
…
…
…
This directory contains the GNU Compiler Collection (GCC). The GNU Compiler Collection is free software. See the files whose names start with COPYING for copying permission. The manuals, and some of the runtime libraries, are under different terms; see the individual source files for details. The directory INSTALL contains copies of the installation information as HTML and plain text. The source of this information is gcc/doc/install.texi. The installation information includes details of what is included in the GCC sources and what files GCC installs. See the file gcc/doc/gcc.texi (together with other files that it includes) for usage and porting information. An online readable version of the manual is in the files gcc/doc/gcc.info*. See http://gcc.gnu.org/bugs/ for how to report bugs usefully. Copyright years on GCC source files may be listed using range notation, e.g., 1987-2012, indicating that every year in the range, inclusive, is a copyrightable year that could otherwise be listed individually.
Description
Languages
C++
31.9%
C
31.3%
Ada
12%
D
6.5%
Go
6.4%
Other
11.5%