]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/optional/assignment/6.cc
1 // { dg-do run { target c++14 } }
3 // Copyright (C) 2013-2023 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 #include <experimental/optional>
21 #include <testsuite_hooks.h>
27 mixin_counter() { ++counter
; }
28 mixin_counter(mixin_counter
const&) { ++counter
; }
29 ~mixin_counter() { --counter
; }
32 struct value_type
: private mixin_counter
34 value_type() = default;
35 value_type(int) : state(1) { }
36 value_type(std::initializer_list
<char>, const char*) : state(2) { }
42 using O
= std::experimental::optional
<value_type
>;
49 VERIFY( o
&& o
->state
== 0 );
52 O o
{ std::experimental::in_place
, 0 };
54 VERIFY( o
&& o
->state
== 0 );
60 VERIFY( o
&& o
->state
== 1 );
63 O o
{ std::experimental::in_place
};
65 VERIFY( o
&& o
->state
== 1 );
70 o
.emplace({ 'a' }, "");
71 VERIFY( o
&& o
->state
== 2 );
74 O o
{ std::experimental::in_place
};
75 o
.emplace({ 'a' }, "");
76 VERIFY( o
&& o
->state
== 2 );
79 static_assert( !std::is_constructible
<O
, std::initializer_list
<int>, int>(), "" );
81 VERIFY( counter
== 0 );