]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/map/operators/2.cc
re PR c++/59378 (Internal compiler error when using __builtin_shuffle in a template...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / map / operators / 2.cc
1 // Copyright (C) 2012-2013 Free Software Foundation, Inc.
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 // This test verifies that the value type of a map need not be default copyable.
19
20 // { dg-options "-std=c++11" }
21
22 #include <map>
23 #include <testsuite_hooks.h>
24 #include <testsuite_rvalref.h>
25 #include <testsuite_counter_type.h>
26
27 struct Mapped
28 {
29 Mapped() = default;
30 explicit Mapped(const Mapped&) = default;
31 };
32
33 struct DefaultConstructibleType
34 {
35 int val;
36
37 DefaultConstructibleType() : val(123)
38 {}
39
40 DefaultConstructibleType(const DefaultConstructibleType&) = delete;
41 DefaultConstructibleType(DefaultConstructibleType&&) = delete;
42
43 DefaultConstructibleType& operator=(int x)
44 {
45 val = x;
46 return *this;
47 }
48 };
49
50 void test01()
51 {
52 bool test __attribute__((unused)) = true;
53
54 using __gnu_test::rvalstruct;
55 using __gnu_test::counter_type;
56
57 std::map<int, Mapped> m1;
58 m1[0] = Mapped();
59
60 std::map<int, rvalstruct> m2;
61 m2[0] = rvalstruct(13);
62
63 std::map<int, DefaultConstructibleType> m3;
64 VERIFY( m3[0].val == 123 );
65 VERIFY( m3.size() == 1 );
66 m3[0] = 2;
67 VERIFY( m3[0].val == 2 );
68
69 std::map<counter_type, int> m4;
70 VERIFY( m4[counter_type(1)] == 0 );
71 VERIFY( counter_type::specialize_count == 1 );
72 VERIFY( counter_type::copy_count == 0 );
73 VERIFY( counter_type::move_count == 1 );
74
75 counter_type k(2);
76 counter_type::reset();
77
78 VERIFY( m4[k] == 0 );
79 VERIFY( counter_type::copy_count == 1 );
80 VERIFY( counter_type::move_count == 0 );
81 }
82
83 int main()
84 {
85 test01();
86 return 0;
87 }