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 ((void)a); // Prevent unused warning 43 ((void)ca); // Prevent unused warning 44 45 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 46 static_assert(sizeof(test(std::forward<A&>(a))) == 1, ""); 47 static_assert(sizeof(test(std::forward<A>(a))) == 4, ""); 48 static_assert(sizeof(test(std::forward<A>(source()))) == 4, ""); 49 50 static_assert(sizeof(test(std::forward<const A&>(a))) == 2, ""); 51 // static_assert(sizeof(test(std::forward<const A&>(source()))) == 2, ""); 52 static_assert(sizeof(test(std::forward<const A>(a))) == 8, ""); 53 static_assert(sizeof(test(std::forward<const A>(source()))) == 8, ""); 54 55 static_assert(sizeof(test(std::forward<const A&>(ca))) == 2, ""); 56 // static_assert(sizeof(test(std::forward<const A&>(csource()))) == 2, ""); 57 static_assert(sizeof(test(std::forward<const A>(ca))) == 8, ""); 58 static_assert(sizeof(test(std::forward<const A>(csource()))) == 8, ""); 59 60 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES 61 62 static_assert(sizeof(test(std::forward<A&>(a))) == 1, ""); 63 static_assert(sizeof(test(std::forward<A>(a))) == 1, ""); 64 // static_assert(sizeof(test(std::forward<A>(source()))) == 2, ""); 65 66 static_assert(sizeof(test(std::forward<const A&>(a))) == 2, ""); 67 static_assert(sizeof(test(std::forward<const A&>(source()))) == 2, ""); 68 static_assert(sizeof(test(std::forward<const A>(a))) == 2, ""); 69 static_assert(sizeof(test(std::forward<const A>(source()))) == 2, ""); 70 71 static_assert(sizeof(test(std::forward<const A&>(ca))) == 2, ""); 72 static_assert(sizeof(test(std::forward<const A&>(csource()))) == 2, ""); 73 static_assert(sizeof(test(std::forward<const A>(ca))) == 2, ""); 74 static_assert(sizeof(test(std::forward<const A>(csource()))) == 2, ""); 75 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 76 77 #if _LIBCPP_STD_VER > 11 78 constexpr int i1 = std::move(23); 79 static_assert(i1 == 23, "" ); 80 constexpr int i2 = std::forward<int>(42); 81 static_assert(i2 == 42, "" ); 82 #endif 83 } 84