]>
Commit | Line | Data |
---|---|---|
8d9254fc | 1 | // Copyright (C) 2017-2020 Free Software Foundation, Inc. |
1dd95239 VV |
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 | ||
af181c91 | 18 | // { dg-options "-std=gnu++17" } |
47df7e19 | 19 | // { dg-do compile { target c++17 } } |
af181c91 | 20 | |
1dd95239 VV |
21 | #include <optional> |
22 | #include <type_traits> | |
23 | ||
24 | struct MoveOnly | |
25 | { | |
26 | MoveOnly() = default; | |
98910bc2 PC |
27 | MoveOnly(MoveOnly&&); |
28 | MoveOnly& operator=(MoveOnly&&); | |
1dd95239 VV |
29 | }; |
30 | ||
31 | int main() | |
32 | { | |
af181c91 JW |
33 | std::optional x = 5; |
34 | static_assert(std::is_same_v<decltype(x), std::optional<int>>); | |
35 | int y = 42; | |
36 | std::optional x2 = y; | |
37 | static_assert(std::is_same_v<decltype(x2), std::optional<int>>); | |
38 | const int z = 666; | |
39 | std::optional x3 = z; | |
40 | static_assert(std::is_same_v<decltype(x3), std::optional<int>>); | |
41 | std::optional mo = MoveOnly(); | |
42 | static_assert(std::is_same_v<decltype(mo), std::optional<MoveOnly>>); | |
43 | mo = MoveOnly(); | |
44 | ||
45 | std::optional copy = x; | |
46 | static_assert(std::is_same_v<decltype(copy), std::optional<int>>); | |
47 | std::optional move = std::move(mo); | |
48 | static_assert(std::is_same_v<decltype(move), std::optional<MoveOnly>>); | |
1dd95239 | 49 | } |