Home | History | Annotate | Download | only in any.cast
      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
     11 
     12 // <experimental/any>
     13 
     14 // template <class ValueType>
     15 // ValueType any_cast(any const &);
     16 
     17 // Try and cast away const.
     18 
     19 #include <experimental/any>
     20 
     21 struct TestType {};
     22 struct TestType2 {};
     23 
     24 int main()
     25 {
     26     using std::experimental::any;
     27     using std::experimental::any_cast;
     28 
     29     any a;
     30 
     31     // expected-error@experimental/any:* 2 {{binding value of type '_Tp' (aka 'const TestType') to reference to type 'TestType' drops 'const' qualifier}}
     32     any_cast<TestType &>(static_cast<any const&>(a)); // expected-note {{requested here}}
     33     any_cast<TestType &&>(static_cast<any const&>(a)); // expected-note {{requested here}}
     34 
     35     // expected-error@experimental/any:* 2 {{binding value of type '_Tp' (aka 'const TestType2') to reference to type 'TestType2' drops 'const' qualifier}}
     36     any_cast<TestType2 &>(static_cast<any const&&>(a)); // expected-note {{requested here}}
     37     any_cast<TestType2 &&>(static_cast<any const&&>(a)); // expected-note {{requested here}}
     38 }
     39