]> 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
a945c346 1// Copyright (C) 2012-2024 Free Software Foundation, Inc.
ea2c1a6d
JW
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
52066eae 18// { dg-do compile { target c++11 } }
ea2c1a6d
JW
19
20// libstdc++/52591
21
22#include <vector>
fd18c76a
JW
23#include <memory>
24#include <type_traits>
ea2c1a6d 25
9425300b
JW
26// Move-assignment of std::vector<T> is allowed for non-MoveAssignable T when
27// the allocator type propagates. As an extension we also allow it if the
28// allocator type is known to always compare equal.
ea2c1a6d
JW
29
30struct C
31{
32 C& operator=(C&&) = delete;
33};
34
9425300b
JW
35void test01()
36{
37 std::vector<C> a;
38 a = std::vector<C>();
39}
40
fd18c76a
JW
41template<typename T>
42struct A1 : std::allocator<T>
43{
44 template<typename U> struct rebind { typedef A1<U> other; };
45
46 A1() = default;
47 template<typename U> A1(const A1<U>&) { }
48
49 using propagate_on_container_move_assignment = std::true_type;
9425300b 50 using is_always_equal = std::false_type;
fd18c76a
JW
51};
52
9425300b 53void test02()
ea2c1a6d 54{
fd18c76a
JW
55 using test_type = std::vector<C, A1<C>>;
56 static_assert(std::is_nothrow_move_assignable<test_type>::value,
57 "vector is nothrow move-assignable if allocator propagates");
58}
59
60template<typename T>
61struct A2 : std::allocator<T>
62{
64c986b4 63 template<typename U> struct rebind { typedef A2<U> other; };
fd18c76a
JW
64
65 A2() = default;
66 template<typename U> A2(const A2<U>&) { }
67
68 using propagate_on_container_move_assignment = std::false_type;
a2b5fdcb 69 using is_always_equal = std::true_type;
fd18c76a
JW
70};
71
9425300b 72void test03()
fd18c76a
JW
73{
74 using test_type = std::vector<C, A2<C>>;
75 static_assert(std::is_nothrow_move_assignable<test_type>::value,
76 "vector is nothrow move-assignable if allocator is always equal");
ea2c1a6d 77}