From 10491e4c0450dc8e01ed9bec6db061c34a352781 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 26 Aug 2016 14:11:29 +0100 Subject: [PATCH] libstdc++/51960 move-construction for raw_storage_iterator PR libstdc++/51960 * doc/xml/manual/intro.xml: Document DR 2127 change. * doc/html/*: Regenerate. * include/bits/stl_raw_storage_iter.h (operator=(_Tp&&)): Add. (operator++(), operator++(int)): Use injected class name. * testsuite/20_util/raw_storage_iterator/dr2127.cc: New test. From-SVN: r239781 --- libstdc++-v3/ChangeLog | 7 +++ libstdc++-v3/doc/html/manual/bugs.html | 3 ++ libstdc++-v3/doc/xml/manual/intro.xml | 6 +++ .../include/bits/stl_raw_storage_iter.h | 17 +++++-- .../20_util/raw_storage_iterator/dr2127.cc | 46 +++++++++++++++++++ 5 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/raw_storage_iterator/dr2127.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 594b9725c50..6b21648fcbd 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,12 @@ 2016-08-26 Jonathan Wakely + PR libstdc++/51960 + * doc/xml/manual/intro.xml: Document DR 2127 change. + * doc/html/*: Regenerate. + * include/bits/stl_raw_storage_iter.h (operator=(_Tp&&)): Add. + (operator++(), operator++(int)): Use injected class name. + * testsuite/20_util/raw_storage_iterator/dr2127.cc: New test. + * testsuite/*: Use { target c++11 } or { target c++14 } instead of using -std in dg-options. diff --git a/libstdc++-v3/doc/html/manual/bugs.html b/libstdc++-v3/doc/html/manual/bugs.html index 14ba1d2506a..de2ad5f1182 100644 --- a/libstdc++-v3/doc/html/manual/bugs.html +++ b/libstdc++-v3/doc/html/manual/bugs.html @@ -390,6 +390,9 @@

2118: unique_ptr for array does not support cv qualification conversion of actual argument

Adjust constraints to allow safe conversions. +

2127: + Move-construction with raw_storage_iterator +

Add assignment operator taking an rvalue.

2132: std::function ambiguity

Constrain the constructor to only accept callable types. diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml index d02306edbf6..238ab241080 100644 --- a/libstdc++-v3/doc/xml/manual/intro.xml +++ b/libstdc++-v3/doc/xml/manual/intro.xml @@ -898,6 +898,12 @@ requirements of the license of GCC. Adjust constraints to allow safe conversions. + 2127: + Move-construction with raw_storage_iterator + + Add assignment operator taking an rvalue. + + 2132: std::function ambiguity diff --git a/libstdc++-v3/include/bits/stl_raw_storage_iter.h b/libstdc++-v3/include/bits/stl_raw_storage_iter.h index 8b5e793dbc4..2d29e7cf533 100644 --- a/libstdc++-v3/include/bits/stl_raw_storage_iter.h +++ b/libstdc++-v3/include/bits/stl_raw_storage_iter.h @@ -86,17 +86,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } - raw_storage_iterator<_OutputIterator, _Tp>& +#if __cplusplus >= 201103L + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2127. Move-construction with raw_storage_iterator + raw_storage_iterator& + operator=(_Tp&& __element) + { + std::_Construct(std::__addressof(*_M_iter), std::move(__element)); + return *this; + } +#endif + + raw_storage_iterator& operator++() { ++_M_iter; return *this; } - raw_storage_iterator<_OutputIterator, _Tp> + raw_storage_iterator operator++(int) { - raw_storage_iterator<_OutputIterator, _Tp> __tmp = *this; + raw_storage_iterator __tmp = *this; ++_M_iter; return __tmp; } diff --git a/libstdc++-v3/testsuite/20_util/raw_storage_iterator/dr2127.cc b/libstdc++-v3/testsuite/20_util/raw_storage_iterator/dr2127.cc new file mode 100644 index 00000000000..9a084f6c6b4 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/raw_storage_iterator/dr2127.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2016 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 +// . + +// { dg-do run { target c++11 } } + +#include +#include + +struct MoveOnly +{ + MoveOnly(int i) : i(i) { } + MoveOnly(MoveOnly&&) = default; + int i; +}; + +void +test01() +{ + char buf[sizeof(MoveOnly)*2]; + MoveOnly* addr = (MoveOnly*)buf; + std::raw_storage_iterator iter(addr); + *iter++ = MoveOnly{1}; + *iter++ = MoveOnly{2}; + VERIFY( addr[0].i == 1 ); + VERIFY( addr[1].i == 2 ); +} + +int +main() +{ + test01(); +} -- 2.30.2