1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03, c++11, c++14
13 // constexpr T& optional<T>::operator*() &;
16 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
20 #include <type_traits>
23 #include "test_macros.h"
29 constexpr int test() const& {return 3;}
30 int test() & {return 4;}
31 constexpr int test() const&& {return 5;}
32 int test() && {return 6;}
37 constexpr int test() {return 7;}
50 optional<X> opt; ((void)opt);
51 ASSERT_SAME_TYPE(decltype(*opt), X&);
52 // ASSERT_NOT_NOEXCEPT(*opt);
53 // FIXME: This assertion fails with GCC because it can see that
54 // (A) operator*() is constexpr, and
55 // (B) there is no path through the function that throws.
56 // It's arguable if this is the correct behavior for the noexcept
58 // Regardless this function should still be noexcept(false) because
59 // it has a narrow contract.
63 assert((*opt).test() == 4);
65 static_assert(test() == 7, "");
69 assert((*opt).test() == 3);
72 #endif // _LIBCPP_DEBUG