Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 30 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 31 | |
| 32 | four test(A&&); |
| 33 | eight test(const A&&); |
| 34 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 35 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 36 | |
| 37 | int main() |
| 38 | { |
| 39 | A a; |
| 40 | const A ca = A(); |
| 41 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 42 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 57 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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, ""); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 72 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Marshall Clow | 01a0e90 | 2013-07-15 20:46:11 +0000 | [diff] [blame] | 73 | |
| 74 | #if _LIBCPP_STD_VER > 11 |
Howard Hinnant | ab61b2c | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 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, "" ); |
Marshall Clow | 01a0e90 | 2013-07-15 20:46:11 +0000 | [diff] [blame] | 79 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 80 | } |