value.pass.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. // XFAIL: libcpp-no-exceptions
  10. // <optional>
  11. // T& optional<T>::value();
  12. #include <experimental/optional>
  13. #include <type_traits>
  14. #include <cassert>
  15. #if _LIBCPP_STD_VER > 11
  16. using std::experimental::optional;
  17. using std::experimental::bad_optional_access;
  18. struct X
  19. {
  20. X() = default;
  21. X(const X&) = delete;
  22. constexpr int test() const {return 3;}
  23. int test() {return 4;}
  24. };
  25. #endif // _LIBCPP_STD_VER > 11
  26. int main()
  27. {
  28. #if _LIBCPP_STD_VER > 11
  29. {
  30. optional<X> opt;
  31. opt.emplace();
  32. assert(opt.value().test() == 4);
  33. }
  34. {
  35. optional<X> opt;
  36. try
  37. {
  38. opt.value();
  39. assert(false);
  40. }
  41. catch (const bad_optional_access&)
  42. {
  43. }
  44. }
  45. #endif // _LIBCPP_STD_VER > 11
  46. }