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