58 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410// <optional>11 12// T shall be an object type and shall satisfy the requirements of Destructible13 14#include <optional>15 16#include "test_macros.h"17 18using std::optional;19 20struct X21{22private:23 ~X() {}24};25 26int main(int, char**)27{28 using std::optional;29 {30#if TEST_STD_VER >= 2631 // expected-error-re@optional:* {{static assertion failed{{.*}}instantiation of optional with an rvalue reference type is ill-formed}}32#else33 // expected-error-re@optional:* 2 {{static assertion failed{{.*}}instantiation of optional with a reference type is ill-formed}}34#endif35 optional<int&> opt1;36 optional<int&&> opt2;37 }38 {39 // expected-error-re@optional:* {{static assertion failed{{.*}}instantiation of optional with a non-destructible type is ill-formed}}40 optional<X> opt3;41 }42 {43 // expected-error-re@optional:* {{static assertion failed{{.*}}instantiation of optional with a non-object type is undefined behavior}}44 // expected-error-re@optional:* {{static assertion failed{{.*}}instantiation of optional with a non-destructible type is ill-formed}}45 optional<void()> opt4;46 }47 {48 // expected-error-re@optional:* {{static assertion failed{{.*}}instantiation of optional with a non-object type is undefined behavior}}49 // expected-error-re@optional:* {{static assertion failed{{.*}}instantiation of optional with a non-destructible type is ill-formed}}50 // expected-error@optional:* 1+ {{cannot form a reference to 'void'}}51 optional<const void> opt4;52 }53 // FIXME these are garbage diagnostics that Clang should not produce54 // expected-error@optional:* 0+ {{is not a base class}}55 56 return 0;57}58