1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14
10 // <optional>
11 
12 // constexpr T&& optional<T>::operator*() const &&;
13 
14 #include <optional>
15 #include <type_traits>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 
20 using std::optional;
21 
22 struct X
23 {
24     constexpr int test() const& {return 3;}
25     int test() & {return 4;}
26     constexpr int test() const&& {return 5;}
27     int test() && {return 6;}
28 };
29 
30 struct Y
31 {
32     int test() const && {return 2;}
33 };
34 
35 int main(int, char**)
36 {
37     {
38         const optional<X> opt; ((void)opt);
39         ASSERT_SAME_TYPE(decltype(*std::move(opt)), X const &&);
40         ASSERT_NOEXCEPT(*std::move(opt));
41     }
42     {
43         constexpr optional<X> opt(X{});
44         static_assert((*std::move(opt)).test() == 5, "");
45     }
46     {
47         constexpr optional<Y> opt(Y{});
48         assert((*std::move(opt)).test() == 2);
49     }
50 
51     return 0;
52 }
53