libstdc++: std::iterator is deprecated since C++17
Jonathan Wakely
jwakely@redhat.com
Tue Oct 20 14:39:49 GMT 2020
Patches for libstdc++ need to be sent to both the gcc-patches list and
libstdc++ list, or they will be ignored.
Removing the std::iterator base classes is an ABI break, so not
acceptable.
std::iterator is deprecated, but that doesn't the library can't use
it. Even after it gets removed, we can continue to define it as a
non-standard extension, see the similar comments at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91260
If you want to add deprecated warnings to std::iterator that's fine,
but you'll need to also use #pragma to prevent uses within libstdc++
from giving any warnings.
One way to do that would be to introduce a new class template that
uses std::iterator and replaces all uses of std::iterator with that:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated"
template<typename _Category, typename _Tp, typename _Distance = ptrdiff_t,
typename _Pointer = _Tp*, typename _Reference = _Tp&>
struct __iterator
: iterator<_Category, _Tp, _Distance, _Pointer, _Reference>
{ };
#pragma GCC diagnostic pop
Ths will allow the library to use it without warnings, but user code
that refers to std::iterator will get warnings.
That would be a much simpler patch too.
We could also consider making it an alias template for C++11, to avoid
the cost of another class template instantiation:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated"
template<typename _Category, typename _Tp, typename _Distance = ptrdiff_t,
typename _Pointer = _Tp*, typename _Reference = _Tp&>
#if __cplusplus < 201103L
struct __iterator
: iterator<_Category, _Tp, _Distance, _Pointer, _Reference>
{ };
#else
using __iterator
= iterator<_Category, _Tp, _Distance, _Pointer, _Reference>;
#pragma GCC diagnostic pop
More information about the Libstdc++
mailing list