dereference.pass.cpp 962 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. // T& optional<T>::operator*();
  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. int test() {return 4;}
  23. };
  24. int main()
  25. {
  26. {
  27. optional<X> opt(X{});
  28. assert((*opt).test() == 4);
  29. }
  30. #ifdef _LIBCPP_DEBUG
  31. {
  32. optional<X> opt;
  33. assert((*opt).test() == 3);
  34. assert(false);
  35. }
  36. #endif // _LIBCPP_DEBUG
  37. }