ctor.fail.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 other than cv in_place_t or cv nullopt_t
  11. // and shall satisfy the Cpp17Destructible requirements.
  12. // Note: array types do not satisfy the Cpp17Destructible requirements.
  13. #include <optional>
  14. #include <type_traits>
  15. #include <cassert>
  16. #include "test_macros.h"
  17. struct NonDestructible { ~NonDestructible() = delete; };
  18. int main(int, char**)
  19. {
  20. {
  21. std::optional<char &> o1; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with a reference type is ill-formed"}}
  22. std::optional<NonDestructible> o2; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with a non-destructible type is ill-formed"}}
  23. std::optional<char[20]> o3; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with an array type is ill-formed"}}
  24. }
  25. {
  26. std::optional< std::in_place_t> o1; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with in_place_t is ill-formed"}}
  27. std::optional<const std::in_place_t> o2; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with in_place_t is ill-formed"}}
  28. std::optional< volatile std::in_place_t> o3; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with in_place_t is ill-formed"}}
  29. std::optional<const volatile std::in_place_t> o4; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with in_place_t is ill-formed"}}
  30. }
  31. {
  32. std::optional< std::nullopt_t> o1; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with nullopt_t is ill-formed"}}
  33. std::optional<const std::nullopt_t> o2; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with nullopt_t is ill-formed"}}
  34. std::optional< volatile std::nullopt_t> o3; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with nullopt_t is ill-formed"}}
  35. std::optional<const volatile std::nullopt_t> o4; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with nullopt_t is ill-formed"}}
  36. }
  37. return 0;
  38. }