optional_requires_destructible_object.fail.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // UNSUPPORTED: c++98, c++03, c++11, c++14
  9. // <optional>
  10. // T shall be an object type and shall satisfy the requirements of Destructible
  11. #include <optional>
  12. using std::optional;
  13. struct X
  14. {
  15. private:
  16. ~X() {}
  17. };
  18. int main(int, char**)
  19. {
  20. using std::optional;
  21. {
  22. // expected-error-re@optional:* 2 {{static_assert failed{{.*}} "instantiation of optional with a reference type is ill-formed}}
  23. optional<int&> opt1;
  24. optional<int&&> opt2;
  25. }
  26. {
  27. // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with a non-destructible type is ill-formed"}}
  28. optional<X> opt3;
  29. }
  30. {
  31. // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with a non-object type is undefined behavior"}}
  32. // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with a non-destructible type is ill-formed}}
  33. optional<void()> opt4;
  34. }
  35. {
  36. // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with a non-object type is undefined behavior"}}
  37. // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with a non-destructible type is ill-formed}}
  38. // expected-error@optional:* 1+ {{cannot form a reference to 'void'}}
  39. optional<const void> opt4;
  40. }
  41. // FIXME these are garbage diagnostics that Clang should not produce
  42. // expected-error@optional:* 0+ {{is not a base class}}
  43. return 0;
  44. }