blob: 357b36fafa96021959423012a3e8d0a552513084 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
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
Howard Hinnant73d21a42010-09-04 23:28:19 +000030#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000031
32four test(A&&);
33eight test(const A&&);
34
Howard Hinnant73d21a42010-09-04 23:28:19 +000035#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000036
37int main()
38{
39 A a;
40 const A ca = A();
41
Howard Hinnant73d21a42010-09-04 23:28:19 +000042#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000043 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
Howard Hinnant73d21a42010-09-04 23:28:19 +000057#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000058
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, "");
Howard Hinnant73d21a42010-09-04 23:28:19 +000072#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Marshall Clow01a0e902013-07-15 20:46:11 +000073
74#if _LIBCPP_STD_VER > 11
Howard Hinnantab61b2c2013-08-07 19:39:48 +000075 constexpr int i1 = std::move(23);
76 static_assert(i1 == 23, "" );
77 constexpr int i2 = std::forward<int>(42);
78 static_assert(i2 == 42, "" );
Marshall Clow01a0e902013-07-15 20:46:11 +000079#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000080}