default.pass.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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() noexcept;
  12. #include <experimental/optional>
  13. #include <type_traits>
  14. #include <cassert>
  15. using std::experimental::optional;
  16. template <class Opt>
  17. void
  18. test_constexpr()
  19. {
  20. static_assert(std::is_nothrow_default_constructible<Opt>::value, "");
  21. constexpr Opt opt;
  22. static_assert(static_cast<bool>(opt) == false, "");
  23. struct test_constexpr_ctor
  24. : public Opt
  25. {
  26. constexpr test_constexpr_ctor() {}
  27. };
  28. }
  29. template <class Opt>
  30. void
  31. test()
  32. {
  33. static_assert(std::is_nothrow_default_constructible<Opt>::value, "");
  34. Opt opt;
  35. assert(static_cast<bool>(opt) == false);
  36. struct test_constexpr_ctor
  37. : public Opt
  38. {
  39. constexpr test_constexpr_ctor() {}
  40. };
  41. }
  42. struct X
  43. {
  44. X();
  45. };
  46. int main()
  47. {
  48. test_constexpr<optional<int>>();
  49. test_constexpr<optional<int*>>();
  50. test<optional<X>>();
  51. }