copy.fail.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // UNSUPPORTED: c++98, c++03, c++11, c++14
  10. // <variant>
  11. // LWG issue 3024
  12. #include <variant>
  13. #include <type_traits>
  14. struct NotCopyConstructible
  15. {
  16. NotCopyConstructible() = default;
  17. NotCopyConstructible(NotCopyConstructible const&) = delete;
  18. };
  19. int main(int, char**)
  20. {
  21. static_assert(!std::is_copy_constructible_v<NotCopyConstructible>);
  22. std::variant<NotCopyConstructible> v;
  23. std::variant<NotCopyConstructible> v1;
  24. std::variant<NotCopyConstructible> v2(v); // expected-error {{call to implicitly-deleted copy constructor of 'std::variant<NotCopyConstructible>'}}
  25. v1 = v; // expected-error-re {{object of type 'std:{{.*}}:variant<NotCopyConstructible>' cannot be assigned because its copy assignment operator is implicitly deleted}}
  26. }