[Bug c++/83226] New: [7 Regression] std::map with reference T breaks in C++17 mode
sgunderson at bigfoot dot com
gcc-bugzilla@gcc.gnu.org
Thu Nov 30 11:55:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83226
Bug ID: 83226
Summary: [7 Regression] std::map with reference T breaks in
C++17 mode
Product: gcc
Version: 7.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: sgunderson at bigfoot dot com
Target Milestone: ---
Hi,
The following code works under GCC for -std=c++14, but breaks under -std=c++17:
#include <map>
#include <utility>
int main(void)
{
std::map<int, const int &> m;
std::pair<int, const int &> val(3, 4);
m.insert(val); // Compile error.
m.emplace(3, 4); // Works.
}
I've looked briefly through the standard, but I can't see anything that
indicates you can't have a const reference as value type (not that I'd
recommend it!). The error messages given are:
In file included from /usr/include/c++/7/bits/stl_iterator.h:66:0,
from /usr/include/c++/7/bits/stl_algobase.h:67,
from /usr/include/c++/7/bits/stl_tree.h:63,
from /usr/include/c++/7/map:60,
from test.cc:1:
/usr/include/c++/7/bits/ptr_traits.h: In substitution of ‘template<class _Tp>
template<class _Up> using rebind = _Up* [with _Up = const int&; _Tp =
std::_Rb_tree_node<std::pair<const int, const int&> >]’:
/usr/include/c++/7/bits/ptr_traits.h:147:77: required by substitution of
‘template<class _Ptr, class _Tp> using __ptr_rebind = typename
std::pointer_traits::rebind<_Tp> [with _Ptr =
std::allocator_traits<std::allocator<std::_Rb_tree_node<std::pair<const int,
const int&> > > >::pointer; _Tp = const int&]’
/usr/include/c++/7/bits/node_handle.h:203:69: required by substitution of
‘template<class _Key, class _Value, class _NodeAlloc> template<class _Tp> using
__pointer = std::__ptr_rebind<typename
std::allocator_traits<_NodeAlloc>::pointer, _Tp> [with _Tp = std::pair<const
int, const int&>::second_type; _Key = int; _Value = std::pair<const int, const
int&>; _NodeAlloc = std::allocator<std::_Rb_tree_node<std::pair<const int,
const int&> > >]’
/usr/include/c++/7/bits/node_handle.h:206:60: required from ‘class
std::_Node_handle<int, std::pair<const int, const int&>,
std::allocator<std::_Rb_tree_node<std::pair<const int, const int&> > > >’
test.cc:8:15: required from here
/usr/include/c++/7/bits/ptr_traits.h:133:28: error: forming pointer to
reference type ‘const int&’
using rebind = _Up*;
^
Confirmed with 20171109 snapshot. Clang 5.0.0 with the same libstdc++ gives a
similar error, so I believe this is about the standard library, not the
compiler (unless it's an invalid program).
GCC 6.4.0 does not give an error here, so I'm marking this as a regression.
More information about the Gcc-bugs
mailing list