diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 1af136e639b..1d0e19a4e51 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2014-04-11 Marc Glisse + + PR libstdc++/59434 + * include/bits/stl_iterator.h (move_iterator::reference, + move_iterator::operator*): Implement LWG 2106. + * testsuite/24_iterators/move_iterator/dr2106.cc: New file. + 2014-04-11 Marc Glisse * include/std/complex (__complex_exp, pow): Specify the template diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 1d2a52419d9..16f992c7490 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -965,6 +965,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Iterator _M_current; typedef iterator_traits<_Iterator> __traits_type; + typedef typename __traits_type::reference __base_ref; public: typedef _Iterator iterator_type; @@ -973,7 +974,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef typename __traits_type::difference_type difference_type; // NB: DR 680. typedef _Iterator pointer; - typedef value_type&& reference; + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2106. move_iterator wrapping iterators returning prvalues + typedef typename conditional::value, + typename remove_reference<__base_ref>::type&&, + __base_ref>::type reference; move_iterator() : _M_current() { } @@ -992,7 +997,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION reference operator*() const - { return std::move(*_M_current); } + { return static_cast(*_M_current); } pointer operator->() const diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/dr2106.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/dr2106.cc new file mode 100644 index 00000000000..fc155620288 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/dr2106.cc @@ -0,0 +1,33 @@ +// { dg-options "-std=gnu++11" } +// { dg-do compile } + +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include + +typedef std::vector Vec; +typedef Vec::reference Ref; +typedef Vec::const_reference CRef; +typedef Vec::iterator It; +typedef Vec::const_iterator CIt; +typedef std::move_iterator MIt; +typedef std::move_iterator MCIt; +static_assert(std::is_same::value,""); +static_assert(std::is_same::value,"");