diff options
author | Eric Fiselier <eric@efcs.ca> | 2014-12-20 01:40:03 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2014-12-20 01:40:03 +0000 |
commit | 5a83710e371fe68a06e6e3876c6a2c8b820a8976 (patch) | |
tree | afde4c82ad6704681781c5cd49baa3fbd05c85db /libcxx/test/std/utilities/utility/forward | |
parent | f11e8eab527fba316c64112f6e05de1a79693a3e (diff) | |
download | bcm5719-llvm-5a83710e371fe68a06e6e3876c6a2c8b820a8976.tar.gz bcm5719-llvm-5a83710e371fe68a06e6e3876c6a2c8b820a8976.zip |
Move test into test/std subdirectory.
llvm-svn: 224658
Diffstat (limited to 'libcxx/test/std/utilities/utility/forward')
14 files changed, 619 insertions, 0 deletions
diff --git a/libcxx/test/std/utilities/utility/forward/forward.pass.cpp b/libcxx/test/std/utilities/utility/forward/forward.pass.cpp new file mode 100644 index 00000000000..357b36fafa9 --- /dev/null +++ b/libcxx/test/std/utilities/utility/forward/forward.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test forward + +#include <utility> +#include <cassert> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +typedef char one; +struct two {one _[2];}; +struct four {one _[4];}; +struct eight {one _[8];}; + +one test(A&); +two test(const A&); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +four test(A&&); +eight test(const A&&); + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ + A a; + const A ca = A(); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + static_assert(sizeof(test(std::forward<A&>(a))) == 1, ""); + static_assert(sizeof(test(std::forward<A>(a))) == 4, ""); + static_assert(sizeof(test(std::forward<A>(source()))) == 4, ""); + + static_assert(sizeof(test(std::forward<const A&>(a))) == 2, ""); +// static_assert(sizeof(test(std::forward<const A&>(source()))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(a))) == 8, ""); + static_assert(sizeof(test(std::forward<const A>(source()))) == 8, ""); + + static_assert(sizeof(test(std::forward<const A&>(ca))) == 2, ""); +// static_assert(sizeof(test(std::forward<const A&>(csource()))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(ca))) == 8, ""); + static_assert(sizeof(test(std::forward<const A>(csource()))) == 8, ""); + +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + static_assert(sizeof(test(std::forward<A&>(a))) == 1, ""); + static_assert(sizeof(test(std::forward<A>(a))) == 1, ""); +// static_assert(sizeof(test(std::forward<A>(source()))) == 2, ""); + + static_assert(sizeof(test(std::forward<const A&>(a))) == 2, ""); + static_assert(sizeof(test(std::forward<const A&>(source()))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(a))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(source()))) == 2, ""); + + static_assert(sizeof(test(std::forward<const A&>(ca))) == 2, ""); + static_assert(sizeof(test(std::forward<const A&>(csource()))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(ca))) == 2, ""); + static_assert(sizeof(test(std::forward<const A>(csource()))) == 2, ""); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#if _LIBCPP_STD_VER > 11 + constexpr int i1 = std::move(23); + static_assert(i1 == 23, "" ); + constexpr int i2 = std::forward<int>(42); + static_assert(i2 == 42, "" ); +#endif +} diff --git a/libcxx/test/std/utilities/utility/forward/forward1.fail.cpp b/libcxx/test/std/utilities/utility/forward/forward1.fail.cpp new file mode 100644 index 00000000000..43884d54bf8 --- /dev/null +++ b/libcxx/test/std/utilities/utility/forward/forward1.fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test forward + +#include <utility> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +int main() +{ + std::forward<A&>(source()); // error +} diff --git a/libcxx/test/std/utilities/utility/forward/forward2.fail.cpp b/libcxx/test/std/utilities/utility/forward/forward2.fail.cpp new file mode 100644 index 00000000000..9ff07233fee --- /dev/null +++ b/libcxx/test/std/utilities/utility/forward/forward2.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test forward + +#include <utility> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +int main() +{ + const A ca = A(); + std::forward<A&>(ca); // error +} diff --git a/libcxx/test/std/utilities/utility/forward/forward3.fail.cpp b/libcxx/test/std/utilities/utility/forward/forward3.fail.cpp new file mode 100644 index 00000000000..7e1e9b38fdc --- /dev/null +++ b/libcxx/test/std/utilities/utility/forward/forward3.fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test forward + +#include <utility> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +int main() +{ + std::forward<A&>(csource()); // error +} diff --git a/libcxx/test/std/utilities/utility/forward/forward4.fail.cpp b/libcxx/test/std/utilities/utility/forward/forward4.fail.cpp new file mode 100644 index 00000000000..276506f811b --- /dev/null +++ b/libcxx/test/std/utilities/utility/forward/forward4.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test forward + +#include <utility> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +int main() +{ + const A ca = A(); + std::forward<A>(ca); // error +} diff --git a/libcxx/test/std/utilities/utility/forward/forward5.fail.cpp b/libcxx/test/std/utilities/utility/forward/forward5.fail.cpp new file mode 100644 index 00000000000..86c2b5651b9 --- /dev/null +++ b/libcxx/test/std/utilities/utility/forward/forward5.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test forward + +#include <utility> + +struct A +{ +}; + +A source() {return A();} +const A csource() {return A();} + +int main() +{ + const A ca = A(); + std::forward<A>(csource()); // error +} diff --git a/libcxx/test/std/utilities/utility/forward/forward6.fail.cpp b/libcxx/test/std/utilities/utility/forward/forward6.fail.cpp new file mode 100644 index 00000000000..1f4b37d946c --- /dev/null +++ b/libcxx/test/std/utilities/utility/forward/forward6.fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test forward + +#include <utility> + +struct A +{ +}; + +int main() +{ + A a; + std::forward(a); // error +} diff --git a/libcxx/test/std/utilities/utility/forward/move_copy.pass.cpp b/libcxx/test/std/utilities/utility/forward/move_copy.pass.cpp new file mode 100644 index 00000000000..461a876cac8 --- /dev/null +++ b/libcxx/test/std/utilities/utility/forward/move_copy.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +int copy_ctor = 0; +int move_ctor = 0; + +class A +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#else +#endif + +public: + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + A(const A&) {++copy_ctor;} + A& operator=(const A&); + + A(A&&) {++move_ctor;} + A& operator=(A&&); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + A(const A&) {++copy_ctor;} + A& operator=(A&); + + operator std::__rv<A> () {return std::__rv<A>(*this);} + A(std::__rv<A>) {++move_ctor;} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + A() {} +}; + +A source() {return A();} +const A csource() {return A();} + +void test(A) {} + +int main() +{ + A a; + const A ca = A(); + + assert(copy_ctor == 0); + assert(move_ctor == 0); + + A a2 = a; + assert(copy_ctor == 1); + assert(move_ctor == 0); + + A a3 = std::move(a); + assert(copy_ctor == 1); + assert(move_ctor == 1); + + A a4 = ca; + assert(copy_ctor == 2); + assert(move_ctor == 1); + + A a5 = std::move(ca); + assert(copy_ctor == 3); + assert(move_ctor == 1); +} diff --git a/libcxx/test/std/utilities/utility/forward/move_if_noexcept.pass.cpp b/libcxx/test/std/utilities/utility/forward/move_if_noexcept.pass.cpp new file mode 100644 index 00000000000..f94ff2a6097 --- /dev/null +++ b/libcxx/test/std/utilities/utility/forward/move_if_noexcept.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <utility> + +// template <class T> +// typename conditional +// < +// !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value, +// const T&, +// T&& +// >::type +// move_if_noexcept(T& x); + +#include <utility> + +class A +{ + A(const A&); + A& operator=(const A&); +public: + + A() {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + A(A&&) {} +#endif +}; + +struct legacy +{ + legacy() {} + legacy(const legacy&); +}; + +int main() +{ + int i = 0; + const int ci = 0; + + legacy l; + A a; + const A ca; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + static_assert((std::is_same<decltype(std::move_if_noexcept(i)), int&&>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(ci)), const int&&>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(a)), A&&>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A&&>::value), ""); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + static_assert((std::is_same<decltype(std::move_if_noexcept(i)), const int>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(ci)), const int>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(a)), const A>::value), ""); + static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A>::value), ""); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + static_assert((std::is_same<decltype(std::move_if_noexcept(l)), const legacy&>::value), ""); + +#if _LIBCPP_STD_VER > 11 + constexpr int i1 = 23; + constexpr int i2 = std::move_if_noexcept(i1); + static_assert(i2 == 23, "" ); +#endif + +} diff --git a/libcxx/test/std/utilities/utility/forward/move_only.pass.cpp b/libcxx/test/std/utilities/utility/forward/move_only.pass.cpp new file mode 100644 index 00000000000..0588c110f1d --- /dev/null +++ b/libcxx/test/std/utilities/utility/forward/move_only.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +class move_only +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(const move_only&); + move_only& operator=(const move_only&); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&); + move_only& operator=(move_only&); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +public: + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&&) {} + move_only& operator=(move_only&&) {return *this;} +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + move_only() {} +}; + +move_only source() {return move_only();} +const move_only csource() {return move_only();} + +void test(move_only) {} + +int main() +{ + move_only mo; + + test(std::move(mo)); + test(source()); +} diff --git a/libcxx/test/std/utilities/utility/forward/move_only1.fail.cpp b/libcxx/test/std/utilities/utility/forward/move_only1.fail.cpp new file mode 100644 index 00000000000..5e7623a1bd1 --- /dev/null +++ b/libcxx/test/std/utilities/utility/forward/move_only1.fail.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +#include <typeinfo> +#include <stdio.h> + +class move_only +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(const move_only&); + move_only& operator=(const move_only&); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&); + move_only& operator=(move_only&); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +public: + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&&) {} + move_only& operator=(move_only&&) {} +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + move_only() {} +}; + +move_only source() {return move_only();} +const move_only csource() {return move_only();} + +void test(move_only) {} + +int main() +{ + move_only a; + const move_only ca = move_only(); + + test(a); +} diff --git a/libcxx/test/std/utilities/utility/forward/move_only2.fail.cpp b/libcxx/test/std/utilities/utility/forward/move_only2.fail.cpp new file mode 100644 index 00000000000..2043f3d4bde --- /dev/null +++ b/libcxx/test/std/utilities/utility/forward/move_only2.fail.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +#include <typeinfo> +#include <stdio.h> + +class move_only +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(const move_only&); + move_only& operator=(const move_only&); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&); + move_only& operator=(move_only&); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +public: + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&&) {} + move_only& operator=(move_only&&) {} +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + move_only() {} +}; + +move_only source() {return move_only();} +const move_only csource() {return move_only();} + +void test(move_only) {} + +int main() +{ + move_only a; + const move_only ca = move_only(); + + test(ca); +} diff --git a/libcxx/test/std/utilities/utility/forward/move_only3.fail.cpp b/libcxx/test/std/utilities/utility/forward/move_only3.fail.cpp new file mode 100644 index 00000000000..84c83ae48f8 --- /dev/null +++ b/libcxx/test/std/utilities/utility/forward/move_only3.fail.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +class move_only +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(const move_only&); + move_only& operator=(const move_only&); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&); + move_only& operator=(move_only&); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +public: + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&&) {} + move_only& operator=(move_only&&) {} +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + move_only() {} +}; + +move_only source() {return move_only();} +const move_only csource() {return move_only();} + +void test(move_only) {} + +int main() +{ + move_only a; + const move_only ca = move_only(); + + test(std::move(ca)); +} diff --git a/libcxx/test/std/utilities/utility/forward/move_only4.fail.cpp b/libcxx/test/std/utilities/utility/forward/move_only4.fail.cpp new file mode 100644 index 00000000000..5eeca89abe3 --- /dev/null +++ b/libcxx/test/std/utilities/utility/forward/move_only4.fail.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test move + +#include <utility> +#include <cassert> + +#include <typeinfo> +#include <stdio.h> + +class move_only +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(const move_only&); + move_only& operator=(const move_only&); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&); + move_only& operator=(move_only&); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +public: + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + move_only(move_only&&) {} + move_only& operator=(move_only&&) {} +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + move_only() {} +}; + +move_only source() {return move_only();} +const move_only csource() {return move_only();} + +void test(move_only) {} + +int main() +{ + move_only a; + const move_only ca = move_only(); + + test(csource()); +} |