nullopt_t.pass.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // UNSUPPORTED: c++98, c++03, c++11
  10. // <optional>
  11. // constexpr optional(nullopt_t) noexcept;
  12. #include <experimental/optional>
  13. #include <type_traits>
  14. #include <cassert>
  15. using std::experimental::optional;
  16. using std::experimental::nullopt_t;
  17. using std::experimental::nullopt;
  18. template <class Opt>
  19. void
  20. test_constexpr()
  21. {
  22. static_assert(noexcept(Opt(nullopt)), "");
  23. constexpr Opt opt(nullopt);
  24. static_assert(static_cast<bool>(opt) == false, "");
  25. struct test_constexpr_ctor
  26. : public Opt
  27. {
  28. constexpr test_constexpr_ctor() {}
  29. };
  30. }
  31. template <class Opt>
  32. void
  33. test()
  34. {
  35. static_assert(noexcept(Opt(nullopt)), "");
  36. Opt opt(nullopt);
  37. assert(static_cast<bool>(opt) == false);
  38. struct test_constexpr_ctor
  39. : public Opt
  40. {
  41. constexpr test_constexpr_ctor() {}
  42. };
  43. }
  44. struct X
  45. {
  46. X();
  47. };
  48. int main()
  49. {
  50. test_constexpr<optional<int>>();
  51. test_constexpr<optional<int*>>();
  52. test<optional<X>>();
  53. }