12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- //===----------------------------------------------------------------------===//
- //
- // 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
- // <optional>
- // constexpr optional(nullopt_t) noexcept;
- #include <optional>
- #include <type_traits>
- #include <cassert>
- #include "archetypes.hpp"
- using std::optional;
- using std::nullopt_t;
- using std::nullopt;
- template <class Opt>
- void
- test_constexpr()
- {
- static_assert(std::is_nothrow_constructible<Opt, nullopt_t&>::value, "");
- static_assert(std::is_trivially_destructible<Opt>::value, "");
- static_assert(std::is_trivially_destructible<typename Opt::value_type>::value, "");
- constexpr Opt opt(nullopt);
- static_assert(static_cast<bool>(opt) == false, "");
- struct test_constexpr_ctor
- : public Opt
- {
- constexpr test_constexpr_ctor() {}
- };
- }
- template <class Opt>
- void
- test()
- {
- static_assert(std::is_nothrow_constructible<Opt, nullopt_t&>::value, "");
- static_assert(!std::is_trivially_destructible<Opt>::value, "");
- static_assert(!std::is_trivially_destructible<typename Opt::value_type>::value, "");
- {
- Opt opt(nullopt);
- assert(static_cast<bool>(opt) == false);
- }
- {
- const Opt opt(nullopt);
- assert(static_cast<bool>(opt) == false);
- }
- struct test_constexpr_ctor
- : public Opt
- {
- constexpr test_constexpr_ctor() {}
- };
- }
- int main()
- {
- test_constexpr<optional<int>>();
- test_constexpr<optional<int*>>();
- test_constexpr<optional<ImplicitTypes::NoCtors>>();
- test_constexpr<optional<NonTrivialTypes::NoCtors>>();
- test_constexpr<optional<NonConstexprTypes::NoCtors>>();
- test<optional<NonLiteralTypes::NoCtors>>();
- }
|