RFC: Remove <bits/boost_concept_check.h> and _GLIBCXX_CONCEPT_CHECKS

Jonathan Wakely jwakely@redhat.com
Fri Sep 24 12:29:28 GMT 2021


I would like to remove the feature described at
https://gcc.gnu.org/onlinedocs/libstdc++/manual/concept_checking.html

As it says at the end of that page, the checks have never been updated
for C++11 requirements, which were relaxed in many ways (e.g. only
requiring movable not copyable).

Currently if you enable the concept checks there are a little over a
hundred test failures (fewer than I was expecting!). Many of these are
because we have extensions like allowing the "wrong" allocator to be
used with a container (e.g. vector<int, allocator<long>>) which gets
rejected by the concept checks.

Some of the concepts aren't even correctly defined for C++98, e.g.

template <class _From, class _To>
 struct _ConvertibleConcept
 {
   void __constraints() {
     _To __y _IsUnused = __x;
   }
   _From __x;
 };

This implicitly requires that _To is destructible, but we use it in
places where that isn't required, e.g. std::move_backward and
std::copy_backward. In fact, neither of those requires this concept at
all, they only require assignable. So it's just wrong.

And the diagnostics you get from failed concept checks are not great either:

In file included from
/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/concept_check.h:56,
                from
/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_iterator_base_funcs.h:64,
                from
/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_algobase.h:66,
                from
/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/vector:60,
                from
/home/jwakely/src/gcc/gcc/libstdc++-v3/testsuite/23_containers/vector/allocator/construction.cc:20:
/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/boost_concept_check.h:
In instantiation of 'void __gnu_cxx::_ConvertibleConcept<_From,
_To>::__constraints() [with _From = X; _To = X]':
/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/boost_concept_check.h:62:
  required from 'constexpr void __gnu_cxx::__function_requires() [with
_Concept = __gnu_cxx::_ConvertibleConcept<X, X>]'
/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_algobase.h:889:
  required from '_BI2 std::move_backward(_BI1, _BI1, _BI2) [with _BI1
= X*; _BI2 = X*]'
/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/vector.tcc:534:
  required from 'void std::vector<_Tp,
_Alloc>::_M_fill_insert(std::vector<_Tp, _Alloc>::iterator,
std::vector<_Tp, _Alloc>::size_type, const std::vector<_Tp,
_Alloc>::value_type&) [with _Tp = X; _Alloc = TaggingAllocator<X>;
std::vector<_Tp, _Alloc>::iterator = std::vector<X,
TaggingAllocator<X> >::iterator; std::vector<_Tp, _Alloc>::size_type =
long unsigned int; std::vector<_Tp, _Alloc>::value_type = X]
/home/jwakely/src/gcc/gcc/libstdc++-v3/testsuite/23_containers/vector/allocator/construction.cc:95:
  required from here
/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/boost_concept_check.h:223:
error: use of deleted function 'X::X(const X&)'
/home/jwakely/src/gcc/gcc/libstdc++-v3/testsuite/23_containers/vector/allocator/construction.cc:78:
note: declared here

The error happens inside the <bits/boost_concept_check.h> header, not
from the std::move_backward function where we are trying to enforce
the (wrong) concept. This was clever tech for C++98, but with type
traits and static assertions we can do so much better nowadays.

We could spend time updating all these concepts and auditing that we
use them correctly, or we could leave them broken and unusable for
anything after C++98, or we could remove them. I'd like to remove
them.

In some cases it would be good to add a static_assert (only for C++11
and later, of course) to enforce the *correct* requirements, with much
better diagnostics. But I'd like to do that at the same time as
ripping out these old checks.

Any objections?



More information about the Libstdc++ mailing list