optional_requires_destructible_object.fail.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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, c++14
  10. // <optional>
  11. // T shall be an object type and shall satisfy the requirements of Destructible
  12. #include <optional>
  13. using std::optional;
  14. struct X
  15. {
  16. private:
  17. ~X() {}
  18. };
  19. int main()
  20. {
  21. using std::optional;
  22. {
  23. // expected-error@optional:* 2 {{static_assert failed "instantiation of optional with a reference type is ill-formed}}
  24. optional<int&> opt1;
  25. optional<int&&> opt2;
  26. }
  27. {
  28. // expected-error@optional:* {{static_assert failed "instantiation of optional with a non-destructible type is ill-formed"}}
  29. optional<X> opt3;
  30. }
  31. {
  32. // expected-error@optional:* {{static_assert failed "instantiation of optional with a non-object type is undefined behavior"}}
  33. // expected-error@optional:* {{static_assert failed "instantiation of optional with a non-destructible type is ill-formed}}
  34. optional<void()> opt4;
  35. }
  36. {
  37. // expected-error@optional:* {{static_assert failed "instantiation of optional with a non-object type is undefined behavior"}}
  38. // expected-error@optional:* {{static_assert failed "instantiation of optional with a non-destructible type is ill-formed}}
  39. // expected-error@optional:* 1+ {{cannot form a reference to 'void'}}
  40. optional<const void> opt4;
  41. }
  42. // FIXME these are garbage diagnostics that Clang should not produce
  43. // expected-error@optional:* 0+ {{is not a base class}}
  44. }