]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/vector/52591.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / vector / 52591.cc
CommitLineData
f1717362 1// Copyright (C) 2012-2016 Free Software Foundation, Inc.
521b90ea 2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17
18// { dg-do compile }
8868286e 19// { dg-options "-std=gnu++11" }
521b90ea 20
21// libstdc++/52591
22
23#include <vector>
65d8ffc2 24#include <memory>
25#include <type_traits>
521b90ea 26
27// As an extension we allow move-assignment of std::vector when the element
28// type is not MoveAssignable, as long as the allocator type propagates or
29// is known to always compare equal.
30
31struct C
32{
33 C& operator=(C&&) = delete;
34};
35
65d8ffc2 36template<typename T>
37struct A1 : std::allocator<T>
38{
39 template<typename U> struct rebind { typedef A1<U> other; };
40
41 A1() = default;
42 template<typename U> A1(const A1<U>&) { }
43
44 using propagate_on_container_move_assignment = std::true_type;
45};
46
521b90ea 47void test01()
48{
65d8ffc2 49 using test_type = std::vector<C, A1<C>>;
50 static_assert(std::is_nothrow_move_assignable<test_type>::value,
51 "vector is nothrow move-assignable if allocator propagates");
52}
53
54template<typename T>
55struct A2 : std::allocator<T>
56{
57 template<typename U> struct rebind { typedef A1<U> other; };
58
59 A2() = default;
60 template<typename U> A2(const A2<U>&) { }
61
62 using propagate_on_container_move_assignment = std::false_type;
141d9a97 63 using is_always_equal = std::true_type;
65d8ffc2 64};
65
65d8ffc2 66void test02()
67{
68 using test_type = std::vector<C, A2<C>>;
69 static_assert(std::is_nothrow_move_assignable<test_type>::value,
70 "vector is nothrow move-assignable if allocator is always equal");
521b90ea 71}