aboutsummaryrefslogtreecommitdiff
path: root/test/std/experimental/any/any.nonmembers/any.cast/const_correctness.fail.cpp
blob: db5149265ccc14fd821cc413e132a9ff566e2bfb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++98, c++03, c++11

// <experimental/any>

// template <class ValueType>
// ValueType any_cast(any const &);

// Try and cast away const.

#include <experimental/any>

struct TestType {};
struct TestType2 {};

int main()
{
    using std::experimental::any;
    using std::experimental::any_cast;

    any a;

    // expected-error@experimental/any:* 2 {{binding value of type '_Tp' (aka 'const TestType') to reference to type 'TestType' drops 'const' qualifier}}
    any_cast<TestType &>(static_cast<any const&>(a)); // expected-note {{requested here}}
    any_cast<TestType &&>(static_cast<any const&>(a)); // expected-note {{requested here}}

    // expected-error@experimental/any:* 2 {{binding value of type '_Tp' (aka 'const TestType2') to reference to type 'TestType2' drops 'const' qualifier}}
    any_cast<TestType2 &>(static_cast<any const&&>(a)); // expected-note {{requested here}}
    any_cast<TestType2 &&>(static_cast<any const&&>(a)); // expected-note {{requested here}}
}