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++98, c++03, c++11, c++14 11 // UNSUPPORTED: clang-5, apple-clang-9 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 // optional(T) 31 std::optional opt(5); 32 static_assert(std::is_same_v<decltype(opt), std::optional<int>>, ""); 33 assert(static_cast<bool>(opt)); 34 assert(*opt == 5); 35 } 36 37 { 38 // optional(T) 39 std::optional opt(A{}); 40 static_assert(std::is_same_v<decltype(opt), std::optional<A>>, ""); 41 assert(static_cast<bool>(opt)); 42 } 43 44 // Test the implicit deduction guides 45 { 46 // optional(optional); 47 std::optional<char> source('A'); 48 std::optional opt(source); 49 static_assert(std::is_same_v<decltype(opt), std::optional<char>>, ""); 50 assert(static_cast<bool>(opt) == static_cast<bool>(source)); 51 assert(*opt == *source); 52 } 53 54 return 0; 55 } 56