deduct.fail.cpp 1.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. // <optional>
  9. // UNSUPPORTED: c++98, c++03, c++11, c++14
  10. // UNSUPPORTED: clang-5
  11. // UNSUPPORTED: libcpp-no-deduction-guides
  12. // Clang 5 will generate bad implicit deduction guides
  13. // Specifically, for the copy constructor.
  14. // template<class T>
  15. // optional(T) -> optional<T>;
  16. #include <optional>
  17. #include <cassert>
  18. struct A {};
  19. int main(int, char**)
  20. {
  21. // Test the explicit deduction guides
  22. // Test the implicit deduction guides
  23. {
  24. // optional()
  25. std::optional opt; // expected-error-re {{{{declaration of variable 'opt' with deduced type 'std::optional' requires an initializer|no viable constructor or deduction guide for deduction of template arguments of 'optional'}}}}
  26. // clang-6 gives a bogus error here:
  27. // declaration of variable 'opt' with deduced type 'std::optional' requires an initializer
  28. // clang-7 (and later) give a better message:
  29. // no viable constructor or deduction guide for deduction of template arguments of 'optional'
  30. // So we check for one or the other.
  31. }
  32. {
  33. // optional(nullopt_t)
  34. std::optional opt(std::nullopt); // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with nullopt_t is ill-formed"}}
  35. }
  36. return 0;
  37. }