brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 71d4d05 Raw
74 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() noexcept;13 14#include <cassert>15#include <optional>16#include <type_traits>17 18#include "test_macros.h"19#include "archetypes.h"20 21using std::optional;22 23template <class Opt>24void test_constexpr() {25  static_assert(std::is_nothrow_default_constructible<Opt>::value, "");26  static_assert(std::is_trivially_destructible<Opt>::value, "");27  static_assert(std::is_trivially_destructible<typename Opt::value_type>::value, "");28 29  constexpr Opt opt;30  static_assert(static_cast<bool>(opt) == false, "");31 32  struct test_constexpr_ctor : public Opt {33    constexpr test_constexpr_ctor() {}34  };35}36 37template <class Opt>38void test() {39  static_assert(std::is_nothrow_default_constructible<Opt>::value, "");40  static_assert(!std::is_trivially_destructible<Opt>::value, "");41  static_assert(!std::is_trivially_destructible<typename Opt::value_type>::value, "");42  {43    Opt opt;44    assert(static_cast<bool>(opt) == false);45  }46  {47    const Opt opt;48    assert(static_cast<bool>(opt) == false);49  }50 51  struct test_constexpr_ctor : public Opt {52    constexpr test_constexpr_ctor() {}53  };54}55 56int main(int, char**) {57  test_constexpr<optional<int>>();58  test_constexpr<optional<int*>>();59  test_constexpr<optional<ImplicitTypes::NoCtors>>();60  test_constexpr<optional<NonTrivialTypes::NoCtors>>();61  test_constexpr<optional<NonConstexprTypes::NoCtors>>();62  test<optional<NonLiteralTypes::NoCtors>>();63  // EXTENSIONS64#if defined(_LIBCPP_VERSION) && 0 // FIXME these extensions are currently disabled.65  test_constexpr<optional<int&>>();66  test_constexpr<optional<const int&>>();67  test_constexpr<optional<int&>>();68  test_constexpr<optional<NonLiteralTypes::NoCtors&>>();69  test_constexpr<optional<NonLiteralTypes::NoCtors&&>>();70#endif71 72  return 0;73}74