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 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 <experimental/any>
     26 
     27 using std::experimental::any;
     28 using std::experimental::any_cast;
     29 
     30 struct no_copy
     31 {
     32     no_copy() {}
     33     no_copy(no_copy &&) {}
     34 private:
     35     no_copy(no_copy const &);
     36 };
     37 
     38 int main() {
     39     any a;
     40     any_cast<no_copy>(static_cast<any&>(a));
     41     any_cast<no_copy>(static_cast<any const&>(a));
     42     any_cast<no_copy>(static_cast<any &&>(a));
     43     // expected-error@experimental/any:* 3 {{static_assert failed "_ValueType is required to be a reference or a CopyConstructible type."}}
     44     // expected-error@experimental/any:* 3 {{calling a private constructor of class 'no_copy'}}
     45 }