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 // UNSUPPORTED: c++98, c++03, c++11, c++14 10 // <optional> 11 12 // T shall be an object type other than cv in_place_t or cv nullopt_t 13 // and shall satisfy the Cpp17Destructible requirements. 14 // Note: array types do not satisfy the Cpp17Destructible requirements. 15 16 #include <optional> 17 #include <type_traits> 18 #include <cassert> 19 20 #include "test_macros.h" 21 22 struct NonDestructible { ~NonDestructible() = delete; }; 23 24 int main(int, char**) 25 { 26 { 27 std::optional<char &> o1; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with a reference type is ill-formed"}} 28 std::optional<NonDestructible> o2; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with a non-destructible type is ill-formed"}} 29 std::optional<char[20]> o3; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with an array type is ill-formed"}} 30 } 31 32 { 33 std::optional< std::in_place_t> o1; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with in_place_t is ill-formed"}} 34 std::optional<const std::in_place_t> o2; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with in_place_t is ill-formed"}} 35 std::optional< volatile std::in_place_t> o3; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with in_place_t is ill-formed"}} 36 std::optional<const volatile std::in_place_t> o4; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with in_place_t is ill-formed"}} 37 } 38 39 { 40 std::optional< std::nullopt_t> o1; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with nullopt_t is ill-formed"}} 41 std::optional<const std::nullopt_t> o2; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with nullopt_t is ill-formed"}} 42 std::optional< volatile std::nullopt_t> o3; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with nullopt_t is ill-formed"}} 43 std::optional<const volatile std::nullopt_t> o4; // expected-error-re@optional:* {{static_assert failed{{.*}} "instantiation of optional with nullopt_t is ill-formed"}} 44 } 45 46 return 0; 47 } 48