op_arrow.pass.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. // <optional>
  10. // constexpr T* optional<T>::operator->();
  11. #ifdef _LIBCPP_DEBUG
  12. #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
  13. #endif
  14. #include <experimental/optional>
  15. #include <type_traits>
  16. #include <cassert>
  17. #if _LIBCPP_STD_VER > 11
  18. using std::experimental::optional;
  19. struct X
  20. {
  21. #if _LIBCPP_STD_VER > 14
  22. constexpr int test() const {return 3;}
  23. #else
  24. constexpr int test() {return 3;}
  25. #endif
  26. };
  27. #endif // _LIBCPP_STD_VER > 11
  28. int main()
  29. {
  30. #if _LIBCPP_STD_VER > 11
  31. {
  32. constexpr optional<X> opt(X{});
  33. static_assert(opt->test() == 3, "");
  34. }
  35. #ifdef _LIBCPP_DEBUG
  36. {
  37. optional<X> opt;
  38. assert(opt->test() == 3);
  39. assert(false);
  40. }
  41. #endif // _LIBCPP_DEBUG
  42. #endif // _LIBCPP_STD_VER > 11
  43. }