value.pass.cpp 1.3 KB

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