brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · c1bdd81 Raw
68 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410// <optional>11 12// constexpr optional(nullopt_t) noexcept;13 14#include <cassert>15#include <optional>16#include <type_traits>17 18#include "archetypes.h"19 20#include "test_macros.h"21 22using std::nullopt;23using std::nullopt_t;24using std::optional;25 26template <class Opt>27void test_constexpr() {28  static_assert(std::is_nothrow_constructible<Opt, nullopt_t&>::value, "");29  static_assert(std::is_trivially_destructible<Opt>::value, "");30  static_assert(std::is_trivially_destructible<typename Opt::value_type>::value, "");31 32  constexpr Opt opt(nullopt);33  static_assert(static_cast<bool>(opt) == false, "");34 35  struct test_constexpr_ctor : public Opt {36    constexpr test_constexpr_ctor() {}37  };38}39 40template <class Opt>41void test() {42  static_assert(std::is_nothrow_constructible<Opt, nullopt_t&>::value, "");43  static_assert(!std::is_trivially_destructible<Opt>::value, "");44  static_assert(!std::is_trivially_destructible<typename Opt::value_type>::value, "");45  {46    Opt opt(nullopt);47    assert(static_cast<bool>(opt) == false);48  }49  {50    const Opt opt(nullopt);51    assert(static_cast<bool>(opt) == false);52  }53  struct test_constexpr_ctor : public Opt {54    constexpr test_constexpr_ctor() {}55  };56}57 58int main(int, char**) {59  test_constexpr<optional<int>>();60  test_constexpr<optional<int*>>();61  test_constexpr<optional<ImplicitTypes::NoCtors>>();62  test_constexpr<optional<NonTrivialTypes::NoCtors>>();63  test_constexpr<optional<NonConstexprTypes::NoCtors>>();64  test<optional<NonLiteralTypes::NoCtors>>();65 66  return 0;67}68