]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/optional/cons/deduction.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / optional / cons / deduction.cc
CommitLineData
fbd26352 1// Copyright (C) 2017-2019 Free Software Foundation, Inc.
cfae3c6f 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
43b0b3ac 18// { dg-options "-std=gnu++17" }
400f7753 19// { dg-do compile { target c++17 } }
43b0b3ac 20
cfae3c6f 21#include <optional>
22#include <type_traits>
23
24struct MoveOnly
25{
26 MoveOnly() = default;
c252b504 27 MoveOnly(MoveOnly&&);
28 MoveOnly& operator=(MoveOnly&&);
cfae3c6f 29};
30
31int main()
32{
43b0b3ac 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>>);
cfae3c6f 49}