diff options
Diffstat (limited to 'test/std/utilities/function.objects')
9 files changed, 264 insertions, 7 deletions
diff --git a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp index 5b660da617a8f..ac43dd769ed68 100644 --- a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp +++ b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp @@ -42,8 +42,7 @@ struct plus_one } }; -int -main() +int main() { using std::placeholders::_1; diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp index faf4f11573d1f..e9b399a2edd2c 100644 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp @@ -12,7 +12,7 @@ // class function<R(ArgTypes...)> // function(const function& f); -// function(function&& f); +// function(function&& f); // noexcept in C++20 #include <functional> #include <memory> @@ -109,6 +109,10 @@ int main() assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f.target<A>()); assert(f.target<int(*)(int)>() == 0); + LIBCPP_ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f))); +#if TEST_STD_VER > 17 + ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f))); +#endif std::function<int(int)> f2 = std::move(f); assert(A::count == 1); assert(globalMemCounter.checkOutstandingNewEq(1)); @@ -129,6 +133,10 @@ int main() assert(A::count == 1); assert(f.target<A>() == nullptr); assert(f.target<Ref>()); + LIBCPP_ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f))); +#if TEST_STD_VER > 17 + ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f))); +#endif std::function<int(int)> f2(std::move(f)); assert(A::count == 1); assert(f2.target<A>() == nullptr); @@ -144,6 +152,10 @@ int main() std::function<int(int)> f(p); assert(f.target<A>() == nullptr); assert(f.target<Ptr>()); + LIBCPP_ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f))); +#if TEST_STD_VER > 17 + ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f))); +#endif std::function<int(int)> f2(std::move(f)); assert(f2.target<A>() == nullptr); assert(f2.target<Ptr>()); diff --git a/test/std/utilities/function.objects/negators/binary_negate.depr_in_cxx17.fail.cpp b/test/std/utilities/function.objects/negators/binary_negate.depr_in_cxx17.fail.cpp new file mode 100644 index 0000000000000..c8247a1959174 --- /dev/null +++ b/test/std/utilities/function.objects/negators/binary_negate.depr_in_cxx17.fail.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// binary_negate +// deprecated in C++17 + +// UNSUPPORTED: clang-4.0 +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// REQUIRES: verify-support + +// MODULES_DEFINES: _LIBCPP_ENABLE_DEPRECATION_WARNINGS +#define _LIBCPP_ENABLE_DEPRECATION_WARNINGS + +#include <functional> + +#include "test_macros.h" + +struct Predicate { + typedef int first_argument_type; + typedef int second_argument_type; + bool operator()(first_argument_type, second_argument_type) const { return true; } +}; + +int main() { + std::binary_negate<Predicate> f((Predicate())); // expected-error{{'binary_negate<Predicate>' is deprecated}} + (void)f; +} diff --git a/test/std/utilities/function.objects/negators/not1.depr_in_cxx17.fail.cpp b/test/std/utilities/function.objects/negators/not1.depr_in_cxx17.fail.cpp new file mode 100644 index 0000000000000..584d3ab0639fb --- /dev/null +++ b/test/std/utilities/function.objects/negators/not1.depr_in_cxx17.fail.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// not1 +// deprecated in C++17 + +// UNSUPPORTED: clang-4.0 +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// REQUIRES: verify-support + +// MODULES_DEFINES: _LIBCPP_ENABLE_DEPRECATION_WARNINGS +#define _LIBCPP_ENABLE_DEPRECATION_WARNINGS + +#include <functional> + +#include "test_macros.h" + +struct Predicate { + typedef int argument_type; + bool operator()(argument_type) const { return true; } +}; + +int main() { + std::not1(Predicate()); // expected-error{{'not1<Predicate>' is deprecated}} +} diff --git a/test/std/utilities/function.objects/negators/not2.depr_in_cxx17.fail.cpp b/test/std/utilities/function.objects/negators/not2.depr_in_cxx17.fail.cpp new file mode 100644 index 0000000000000..92e3be580aff9 --- /dev/null +++ b/test/std/utilities/function.objects/negators/not2.depr_in_cxx17.fail.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// not2 +// deprecated in C++17 + +// UNSUPPORTED: clang-4.0 +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// REQUIRES: verify-support + +// MODULES_DEFINES: _LIBCPP_ENABLE_DEPRECATION_WARNINGS +#define _LIBCPP_ENABLE_DEPRECATION_WARNINGS + +#include <functional> + +#include "test_macros.h" + +struct Predicate { + typedef int first_argument_type; + typedef int second_argument_type; + bool operator()(first_argument_type, second_argument_type) const { return true; } +}; + +int main() { + std::not2(Predicate()); // expected-error{{'not2<Predicate>' is deprecated}} +} diff --git a/test/std/utilities/function.objects/negators/unary_negate.depr_in_cxx17.fail.cpp b/test/std/utilities/function.objects/negators/unary_negate.depr_in_cxx17.fail.cpp new file mode 100644 index 0000000000000..b38a7d2f1c094 --- /dev/null +++ b/test/std/utilities/function.objects/negators/unary_negate.depr_in_cxx17.fail.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// unary_negate +// deprecated in C++17 + +// UNSUPPORTED: clang-4.0 +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// REQUIRES: verify-support + +// MODULES_DEFINES: _LIBCPP_ENABLE_DEPRECATION_WARNINGS +#define _LIBCPP_ENABLE_DEPRECATION_WARNINGS + +#include <functional> + +#include "test_macros.h" + +struct Predicate { + typedef int argument_type; + bool operator()(argument_type) const { return true; } +}; + +int main() { + std::unary_negate<Predicate> f((Predicate())); // expected-error{{'unary_negate<Predicate>' is deprecated}} + (void)f; +} diff --git a/test/std/utilities/function.objects/refwrap/type_properties.pass.cpp b/test/std/utilities/function.objects/refwrap/type_properties.pass.cpp index 261a306ca156e..27d498ec82829 100644 --- a/test/std/utilities/function.objects/refwrap/type_properties.pass.cpp +++ b/test/std/utilities/function.objects/refwrap/type_properties.pass.cpp @@ -11,11 +11,11 @@ // reference_wrapper -// Test that reference wrapper meets the requirements of TriviallyCopyable, -// CopyConstructible and CopyAssignable. +// Test that reference wrapper meets the requirements of CopyConstructible and +// CopyAssignable, and TriviallyCopyable (starting in C++14). // Test fails due to use of is_trivially_* trait. -// XFAIL: gcc-4.9 +// XFAIL: gcc-4.9 && c++14 #include <functional> #include <type_traits> @@ -48,8 +48,9 @@ void test() typedef std::reference_wrapper<T> Wrap; static_assert(std::is_copy_constructible<Wrap>::value, ""); static_assert(std::is_copy_assignable<Wrap>::value, ""); - // Extension up for standardization: See N4151. +#if TEST_STD_VER >= 14 static_assert(std::is_trivially_copyable<Wrap>::value, ""); +#endif } int main() diff --git a/test/std/utilities/function.objects/refwrap/unwrap_ref_decay.pass.cpp b/test/std/utilities/function.objects/refwrap/unwrap_ref_decay.pass.cpp new file mode 100644 index 0000000000000..a63dc5b15f4bd --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/unwrap_ref_decay.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> +// +// template <class T> +// struct unwrap_ref_decay; +// +// template <class T> +// using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +#include <functional> +#include <type_traits> + + +template <typename T, typename Result> +void check() { + static_assert(std::is_same_v<typename std::unwrap_ref_decay<T>::type, Result>); + static_assert(std::is_same_v<typename std::unwrap_ref_decay<T>::type, std::unwrap_ref_decay_t<T>>); +} + +struct T { }; + +int main() { + check<T, T>(); + check<T&, T>(); + check<T const, T>(); + check<T const&, T>(); + check<T*, T*>(); + check<T const*, T const*>(); + check<T[3], T*>(); + check<T const [3], T const*>(); + check<T (), T (*)()>(); + check<T (int) const, T (int) const>(); + check<T (int) &, T (int) &>(); + check<T (int) &&, T (int) &&>(); + + check<std::reference_wrapper<T>, T&>(); + check<std::reference_wrapper<T>&, T&>(); + check<std::reference_wrapper<T const>, T const&>(); + check<std::reference_wrapper<T const>&, T const&>(); + check<std::reference_wrapper<T*>, T*&>(); + check<std::reference_wrapper<T*>&, T*&>(); + check<std::reference_wrapper<T const*>, T const*&>(); + check<std::reference_wrapper<T const*>&, T const*&>(); + check<std::reference_wrapper<T[3]>, T (&)[3]>(); + check<std::reference_wrapper<T[3]>&, T (&)[3]>(); + check<std::reference_wrapper<T ()>, T (&)()>(); + check<std::reference_wrapper<T ()>&, T (&)()>(); +} diff --git a/test/std/utilities/function.objects/refwrap/unwrap_reference.pass.cpp b/test/std/utilities/function.objects/refwrap/unwrap_reference.pass.cpp new file mode 100644 index 0000000000000..441ddf4bd568f --- /dev/null +++ b/test/std/utilities/function.objects/refwrap/unwrap_reference.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <functional> +// +// template <class T> +// struct unwrap_reference; +// +// template <class T> +// using unwrap_reference_t = typename unwrap_reference<T>::type; + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +#include <functional> +#include <type_traits> + + +template <typename T, typename Expected> +void check_equal() { + static_assert(std::is_same_v<typename std::unwrap_reference<T>::type, Expected>); + static_assert(std::is_same_v<typename std::unwrap_reference<T>::type, std::unwrap_reference_t<T>>); +} + +template <typename T> +void check() { + check_equal<T, T>(); + check_equal<T&, T&>(); + check_equal<T const, T const>(); + check_equal<T const&, T const&>(); + + check_equal<std::reference_wrapper<T>, T&>(); + check_equal<std::reference_wrapper<T const>, T const&>(); +} + +struct T { }; + +int main() { + check<T>(); + check<int>(); + check<float>(); + + check<T*>(); + check<int*>(); + check<float*>(); +} |
