1 // Copyright (C) 2012-2025 Free Software Foundation, Inc.
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)
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.
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/>.
18 // This test verifies that the value type of a map need not be default copyable.
20 // { dg-do run { target c++11 } }
23 #include <testsuite_hooks.h>
24 #include <testsuite_rvalref.h>
25 #include <testsuite_counter_type.h>
30 explicit Mapped(const Mapped
&) = default;
33 struct DefaultConstructibleType
37 DefaultConstructibleType() : val(123)
40 DefaultConstructibleType(const DefaultConstructibleType
&) = delete;
41 DefaultConstructibleType(DefaultConstructibleType
&&) = delete;
43 DefaultConstructibleType
& operator=(int x
)
52 using __gnu_test::rvalstruct
;
53 using __gnu_test::counter_type
;
55 std::map
<int, Mapped
> m1
;
58 std::map
<int, rvalstruct
> m2
;
59 m2
[0] = rvalstruct(13);
61 std::map
<int, DefaultConstructibleType
> m3
;
62 VERIFY( m3
[0].val
== 123 );
63 VERIFY( m3
.size() == 1 );
65 VERIFY( m3
[0].val
== 2 );
67 std::map
<counter_type
, int> m4
;
68 VERIFY( m4
[counter_type(1)] == 0 );
69 VERIFY( counter_type::specialize_count
== 1 );
70 VERIFY( counter_type::copy_count
== 0 );
71 VERIFY( counter_type::move_count
== 1 );
74 counter_type::reset();
77 VERIFY( counter_type::copy_count
== 1 );
78 VERIFY( counter_type::move_count
== 0 );