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 // test forward 11 12 #include <utility> 13 #include <cassert> 14 15 struct A 16 { 17 }; 18 19 A source() {return A();} 20 const A csource() {return A();} 21 22 typedef char one; 23 struct two {one _[2];}; 24 struct four {one _[4];}; 25 struct eight {one _[8];}; 26 27 one test(A&); 28 two test(const A&); 29 30 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 31 32 four test(A&&); 33 eight test(const A&&); 34 35 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 36 37 int main() 38 { 39 A a; 40 const A ca = A(); 41 42 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 43 static_assert(sizeof(test(std::forward<A&>(a))) == 1, ""); 44 static_assert(sizeof(test(std::forward<A>(a))) == 4, ""); 45 static_assert(sizeof(test(std::forward<A>(source()))) == 4, ""); 46 47 static_assert(sizeof(test(std::forward<const A&>(a))) == 2, ""); 48 // static_assert(sizeof(test(std::forward<const A&>(source()))) == 2, ""); 49 static_assert(sizeof(test(std::forward<const A>(a))) == 8, ""); 50 static_assert(sizeof(test(std::forward<const A>(source()))) == 8, ""); 51 52 static_assert(sizeof(test(std::forward<const A&>(ca))) == 2, ""); 53 // static_assert(sizeof(test(std::forward<const A&>(csource()))) == 2, ""); 54 static_assert(sizeof(test(std::forward<const A>(ca))) == 8, ""); 55 static_assert(sizeof(test(std::forward<const A>(csource()))) == 8, ""); 56 57 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 58 59 static_assert(sizeof(test(std::forward<A&>(a))) == 1, ""); 60 static_assert(sizeof(test(std::forward<A>(a))) == 1, ""); 61 // static_assert(sizeof(test(std::forward<A>(source()))) == 2, ""); 62 63 static_assert(sizeof(test(std::forward<const A&>(a))) == 2, ""); 64 static_assert(sizeof(test(std::forward<const A&>(source()))) == 2, ""); 65 static_assert(sizeof(test(std::forward<const A>(a))) == 2, ""); 66 static_assert(sizeof(test(std::forward<const A>(source()))) == 2, ""); 67 68 static_assert(sizeof(test(std::forward<const A&>(ca))) == 2, ""); 69 static_assert(sizeof(test(std::forward<const A&>(csource()))) == 2, ""); 70 static_assert(sizeof(test(std::forward<const A>(ca))) == 2, ""); 71 static_assert(sizeof(test(std::forward<const A>(csource()))) == 2, ""); 72 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 73 74 #if _LIBCPP_STD_VER > 11 75 constexpr int i1 = std::move(23); 76 static_assert(i1 == 23, "" ); 77 constexpr int i2 = std::forward<int>(42); 78 static_assert(i2 == 42, "" ); 79 #endif 80 } 81