forward.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
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 15struct A 16{ 17}; 18 19A source() {return A();} 20const A csource() {return A();} 21 22typedef char one; 23struct two {one _[2];}; 24struct four {one _[4];}; 25struct eight {one _[8];}; 26 27one test(A&); 28two test(const A&); 29 30#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 31 32four test(A&&); 33eight test(const A&&); 34 35#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 36 37int 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