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