//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03 // test forward #include #include #include #include "test_macros.h" struct A { }; A source() noexcept {return A();} const A csource() noexcept {return A();} constexpr bool test_constexpr_forward() { #if TEST_STD_VER > 11 int x = 42; const int cx = 101; return std::forward(x) == 42 && std::forward(x) == 42 && std::forward(x) == 42 && std::forward(x) == 42 && std::forward(x) == 42 && std::forward(x) == 42 && std::forward(cx) == 101 && std::forward(cx) == 101; #else return true; #endif } int main() { A a; const A ca = A(); ((void)a); // Prevent unused warning ((void)ca); // Prevent unused warning static_assert(std::is_same(a)), A&>::value, ""); static_assert(std::is_same(a)), A&&>::value, ""); static_assert(std::is_same(source())), A&&>::value, ""); static_assert(noexcept(std::forward(a)), ""); static_assert(noexcept(std::forward(a)), ""); static_assert(noexcept(std::forward(source())), ""); static_assert(std::is_same(a)), const A&>::value, ""); static_assert(std::is_same(a)), const A&&>::value, ""); static_assert(std::is_same(source())), const A&&>::value, ""); static_assert(noexcept(std::forward(a)), ""); static_assert(noexcept(std::forward(a)), ""); static_assert(noexcept(std::forward(source())), ""); static_assert(std::is_same(ca)), const A&>::value, ""); static_assert(std::is_same(ca)), const A&&>::value, ""); static_assert(std::is_same(csource())), const A&&>::value, ""); static_assert(noexcept(std::forward(ca)), ""); static_assert(noexcept(std::forward(ca)), ""); static_assert(noexcept(std::forward(csource())), ""); #if TEST_STD_VER > 11 { constexpr int i2 = std::forward(42); static_assert(std::forward(42) == 42, ""); static_assert(std::forward(i2) == 42, ""); static_assert(test_constexpr_forward(), ""); } #endif #if TEST_STD_VER == 11 && defined(_LIBCPP_VERSION) // Test that std::forward is constexpr in C++11. This is an extension // provided by both libc++ and libstdc++. { constexpr int i2 = std::forward(42); static_assert(std::forward(42) == 42, "" ); static_assert(std::forward(i2) == 42, ""); } #endif }