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