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