]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/any/any.nonmembers/any.cast/not_copy_constructible.fail.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / utilities / any / any.nonmembers / any.cast / not_copy_constructible.fail.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // UNSUPPORTED: c++98, c++03, c++11, c++14
11
12 // <any>
13
14 // template <class ValueType>
15 // ValueType const any_cast(any const&);
16 //
17 // template <class ValueType>
18 // ValueType any_cast(any &);
19 //
20 // template <class ValueType>
21 // ValueType any_cast(any &&);
22
23 // Test instantiating the any_cast with a non-copyable type.
24
25 #include <any>
26
27 using std::any;
28 using std::any_cast;
29
30 struct no_copy
31 {
32     no_copy() {}
33     no_copy(no_copy &&) {}
34     no_copy(no_copy const &) = delete;
35 };
36
37 struct no_move {
38   no_move() {}
39   no_move(no_move&&) = delete;
40   no_move(no_move const&) {}
41 };
42
43 int main() {
44     any a;
45     // expected-error@any:* {{static_assert failed "ValueType is required to be an lvalue reference or a CopyConstructible type"}}
46     // expected-error@any:* {{static_cast from 'no_copy' to 'no_copy' uses deleted function}}
47     any_cast<no_copy>(static_cast<any&>(a)); // expected-note {{requested here}}
48
49     // expected-error@any:* {{static_assert failed "ValueType is required to be a const lvalue reference or a CopyConstructible type"}}
50     // expected-error@any:* {{static_cast from 'const no_copy' to 'no_copy' uses deleted function}}
51     any_cast<no_copy>(static_cast<any const&>(a)); // expected-note {{requested here}}
52
53     any_cast<no_copy>(static_cast<any &&>(a)); // OK
54
55     // expected-error@any:* {{static_assert failed "ValueType is required to be an rvalue reference or a CopyConstructible type"}}
56     // expected-error@any:* {{static_cast from 'typename remove_reference<no_move &>::type' (aka 'no_move') to 'no_move' uses deleted function}}
57     any_cast<no_move>(static_cast<any &&>(a));
58 }