From 53a420fba21cf1644972b34dcd811a43cdb8368d Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 2 Jan 2017 19:18:58 +0000 Subject: Vendor import of libc++ trunk r290819: https://llvm.org/svn/llvm-project/libcxx/trunk@290819 --- .../optional.object.observe/value_const.pass.cpp | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 test/std/utilities/optional/optional.object/optional.object.observe/value_const.pass.cpp (limited to 'test/std/utilities/optional/optional.object/optional.object.observe/value_const.pass.cpp') diff --git a/test/std/utilities/optional/optional.object/optional.object.observe/value_const.pass.cpp b/test/std/utilities/optional/optional.object/optional.object.observe/value_const.pass.cpp new file mode 100644 index 000000000000..d4038e4efa6b --- /dev/null +++ b/test/std/utilities/optional/optional.object/optional.object.observe/value_const.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// + +// constexpr const T& optional::value() const &; + +#include +#include +#include + +#include "test_macros.h" + +using std::optional; +using std::in_place_t; +using std::in_place; +using std::bad_optional_access; + +struct X +{ + X() = default; + X(const X&) = delete; + constexpr int test() const & {return 3;} + int test() & {return 4;} + constexpr int test() const && {return 5;} + int test() && {return 6;} +}; + +int main() +{ + { + const optional opt; ((void)opt); + ASSERT_NOT_NOEXCEPT(opt.value()); + ASSERT_SAME_TYPE(decltype(opt.value()), X const&); + } + { + constexpr optional opt(in_place); + static_assert(opt.value().test() == 3, ""); + } + { + const optional opt(in_place); + assert(opt.value().test() == 3); + } +#ifndef TEST_HAS_NO_EXCEPTIONS + { + const optional opt; + try + { + opt.value(); + assert(false); + } + catch (const bad_optional_access&) + { + } + } +#endif +} -- cgit v1.3