diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:18:58 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:18:58 +0000 |
| commit | 53a420fba21cf1644972b34dcd811a43cdb8368d (patch) | |
| tree | 66a19f6f8b65215772549a51d688492ab8addc0d /test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con | |
| parent | b50f1549701eb950921e5d6f2e55ba1a1dadbb43 (diff) | |
Notes
Diffstat (limited to 'test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con')
14 files changed, 323 insertions, 47 deletions
diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp index 82a6f6c5215e..fd296a7367b8 100644 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp @@ -16,6 +16,7 @@ #include <functional> #include <cassert> +#include "test_macros.h" #include "count_new.hpp" class A @@ -49,6 +50,17 @@ int A::count = 0; int g(int) {return 0;} +#if TEST_STD_VER >= 11 +struct RValueCallable { + template <class ...Args> + void operator()(Args&&...) && {} +}; +struct LValueCallable { + template <class ...Args> + void operator()(Args&&...) & {} +}; +#endif + int main() { assert(globalMemCounter.checkOutstandingNewEq(0)); @@ -91,4 +103,13 @@ int main() std::function <void()> f(static_cast<void (*)()>(0)); assert(!f); } +#if TEST_STD_VER >= 11 + { + using Fn = std::function<void(int, int, int)>; + static_assert(std::is_constructible<Fn, LValueCallable&>::value, ""); + static_assert(std::is_constructible<Fn, LValueCallable>::value, ""); + static_assert(!std::is_constructible<Fn, RValueCallable&>::value, ""); + static_assert(!std::is_constructible<Fn, RValueCallable>::value, ""); + } +#endif } diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp index 11716e7946b0..e927ad42c06b 100644 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp @@ -19,6 +19,7 @@ #include <functional> #include <cassert> +#include "test_macros.h" #include "count_new.hpp" class A @@ -52,6 +53,17 @@ int A::count = 0; int g(int) {return 0;} +#if TEST_STD_VER >= 11 +struct RValueCallable { + template <class ...Args> + void operator()(Args&&...) && {} +}; +struct LValueCallable { + template <class ...Args> + void operator()(Args&&...) & {} +}; +#endif + int main() { assert(globalMemCounter.checkOutstandingNewEq(0)); @@ -95,4 +107,13 @@ int main() assert(f.target<int(*)(int)>() != 0); f(1); } +#if TEST_STD_VER >= 11 + { + using Fn = std::function<void(int, int, int)>; + static_assert(std::is_assignable<Fn&, LValueCallable&>::value, ""); + static_assert(std::is_assignable<Fn&, LValueCallable>::value, ""); + static_assert(!std::is_assignable<Fn&, RValueCallable&>::value, ""); + static_assert(!std::is_assignable<Fn&, RValueCallable>::value, ""); + } +#endif } diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.fail.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.fail.cpp new file mode 100644 index 000000000000..f455f0311847 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.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. +// +//===----------------------------------------------------------------------===// + +// <functional> +// XFAIL: c++98, c++03, c++11, c++14 + +// class function<R(ArgTypes...)> + +// template<class A> function(allocator_arg_t, const A&); + +#include <functional> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + std::function<int(int)> f(std::allocator_arg, std::allocator<int>()); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp index f97e34d3f2cb..392dfc1993bc 100644 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp @@ -8,10 +8,13 @@ //===----------------------------------------------------------------------===// // <functional> +// REQUIRES-ANY: c++98, c++03, c++11, c++14 // class function<R(ArgTypes...)> // template<class A> function(allocator_arg_t, const A&); +// +// This signature was removed in C++17 #include <functional> #include <cassert> diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.fail.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.fail.cpp new file mode 100644 index 000000000000..24f7fceb877b --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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> +// XFAIL: c++98, c++03, c++11, c++14 + +// class function<R(ArgTypes...)> + +// template<class F, class A> function(allocator_arg_t, const A&, F); +// +// This signature was removed in C++17 + +#include <functional> +#include <cassert> + +#include "test_macros.h" + +void foo(int) {} + +int main() +{ + std::function<void(int)> f(std::allocator_arg, std::allocator<int>(), foo); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp index 352ecfc602be..8d454723320c 100644 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// // <functional> +// REQUIRES-ANY: c++98, c++03, c++11, c++14 // class function<R(ArgTypes...)> @@ -16,11 +17,24 @@ #include <functional> #include <cassert> +#include "test_macros.h" #include "min_allocator.h" #include "test_allocator.h" #include "count_new.hpp" #include "../function_types.h" + +#if TEST_STD_VER >= 11 +struct RValueCallable { + template <class ...Args> + void operator()(Args&&...) && {} +}; +struct LValueCallable { + template <class ...Args> + void operator()(Args&&...) & {} +}; +#endif + class DummyClass {}; template <class FuncType, class AllocType> @@ -103,4 +117,14 @@ int main() non_default_test_allocator<DummyClass> non_default_alloc(42); test_for_alloc(non_default_alloc); } +#if TEST_STD_VER >= 11 + { + using Fn = std::function<void(int, int, int)>; + static_assert(std::is_constructible<Fn, std::allocator_arg_t, std::allocator<int>, LValueCallable&>::value, ""); + static_assert(std::is_constructible<Fn, std::allocator_arg_t, std::allocator<int>, LValueCallable>::value, ""); + static_assert(!std::is_constructible<Fn, std::allocator_arg_t, std::allocator<int>, RValueCallable&>::value, ""); + static_assert(!std::is_constructible<Fn, std::allocator_arg_t, std::allocator<int>, RValueCallable>::value, ""); + } +#endif + } diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.fail.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.fail.cpp new file mode 100644 index 000000000000..9967457ff821 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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> +// XFAIL: c++98, c++03, c++11, c++14 + +// class function<R(ArgTypes...)> + +// template<class A> function(allocator_arg_t, const A&, const function&); +// +// This signature was removed in C++17 + + +#include <functional> +#include <cassert> + +#include "test_macros.h" + +int main() +{ + typedef std::function<void(int)> F; + F f1; + F f2(std::allocator_arg, std::allocator<int>(), f1); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp index 371eb98de1a9..718aa49341d2 100644 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// // <functional> +// REQUIRES-ANY: c++98, c++03, c++11, c++14 // class function<R(ArgTypes...)> diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.fail.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.fail.cpp new file mode 100644 index 000000000000..cc4ecce75138 --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.fail.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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> +// XFAIL: c++98, c++03, c++11, c++14 + +// class function<R(ArgTypes...)> + +// template<class A> function(allocator_arg_t, const A&, nullptr_t); +// +// This signature was removed in C++17 + +#include <functional> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + std::function<int(int)> f(std::allocator_arg, std::allocator<int>(), nullptr); +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp index 2350f92f0f89..354ad955f207 100644 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp @@ -8,10 +8,13 @@ //===----------------------------------------------------------------------===// // <functional> +// REQUIRES-ANY: c++98, c++03, c++11, c++14 // class function<R(ArgTypes...)> // template<class A> function(allocator_arg_t, const A&, nullptr_t); +// +// This signature was removed in C++17 #include <functional> #include <cassert> diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.fail.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.fail.cpp new file mode 100644 index 000000000000..cb9fb9afad2b --- /dev/null +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.fail.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// 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> +// XFAIL: c++98, c++03, c++11, c++14 + +// class function<R(ArgTypes...)> + +// template<class A> function(allocator_arg_t, const A&, function&&); +// +// This signature was removed in C++17 + +#include <functional> +#include <memory> +#include <cassert> + +#include "test_macros.h" + +class A +{ + int data_[10]; +public: + static int count; + + A() + { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } + + A(const A&) {++count;} + + ~A() {--count;} + + int operator()(int i) const + { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } +}; + +int A::count = 0; + +int g(int) { return 0; } + +int main() +{ + { + std::function<int(int)> f = A(); + std::function<int(int)> f2(std::allocator_arg, std::allocator<A>(), std::move(f)); + } +} diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp index 403d646f4216..e328481b274d 100644 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp @@ -8,12 +8,15 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03 +// REQUIRES-ANY: c++11, c++14 // <functional> // class function<R(ArgTypes...)> // template<class A> function(allocator_arg_t, const A&, function&&); +// +// This signature was removed in C++17 #include <functional> #include <memory> diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp index c91eaa2d5674..9b83ddecb974 100644 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp @@ -16,94 +16,123 @@ #include <functional> #include <cassert> +#include "test_macros.h" #include "count_new.hpp" -class A -{ - int data_[10]; +class A { + int data_[10]; + public: - static int count; + static int count; - A() - { - ++count; - for (int i = 0; i < 10; ++i) - data_[i] = i; - } + A() { + ++count; + for (int i = 0; i < 10; ++i) + data_[i] = i; + } - A(const A&) {++count;} + A(const A &) { ++count; } - ~A() {--count;} + ~A() { --count; } - int operator()(int i) const - { - for (int j = 0; j < 10; ++j) - i += data_[j]; - return i; - } + int operator()(int i) const { + for (int j = 0; j < 10; ++j) + i += data_[j]; + return i; + } }; int A::count = 0; -int g(int) {return 0;} +int g0() { return 0; } +int g(int) { return 0; } +int g2(int, int) { return 2; } +int g3(int, int, int) { return 3; } -int main() -{ - assert(globalMemCounter.checkOutstandingNewEq(0)); - { +int main() { + assert(globalMemCounter.checkOutstandingNewEq(0)); + { std::function<int(int)> f = A(); assert(A::count == 1); assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f.target<A>()); - assert(f.target<int(*)(int)>() == 0); + assert(f.target<int (*)(int)>() == 0); std::function<int(int)> f2; f2 = f; assert(A::count == 2); assert(globalMemCounter.checkOutstandingNewEq(2)); assert(f2.target<A>()); - assert(f2.target<int(*)(int)>() == 0); - } - assert(A::count == 0); - assert(globalMemCounter.checkOutstandingNewEq(0)); - { + assert(f2.target<int (*)(int)>() == 0); + } + assert(A::count == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); + { std::function<int(int)> f = g; assert(globalMemCounter.checkOutstandingNewEq(0)); - assert(f.target<int(*)(int)>()); + assert(f.target<int (*)(int)>()); assert(f.target<A>() == 0); std::function<int(int)> f2; f2 = f; assert(globalMemCounter.checkOutstandingNewEq(0)); - assert(f2.target<int(*)(int)>()); + assert(f2.target<int (*)(int)>()); assert(f2.target<A>() == 0); - } - assert(globalMemCounter.checkOutstandingNewEq(0)); - { + } + assert(globalMemCounter.checkOutstandingNewEq(0)); + { std::function<int(int)> f; assert(globalMemCounter.checkOutstandingNewEq(0)); - assert(f.target<int(*)(int)>() == 0); + assert(f.target<int (*)(int)>() == 0); assert(f.target<A>() == 0); std::function<int(int)> f2; f2 = f; assert(globalMemCounter.checkOutstandingNewEq(0)); - assert(f2.target<int(*)(int)>() == 0); + assert(f2.target<int (*)(int)>() == 0); assert(f2.target<A>() == 0); - } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - assert(globalMemCounter.checkOutstandingNewEq(0)); - { + } + { + typedef std::function<int()> Func; + Func f = g0; + Func& fr = (f = f); + assert(&fr == &f); + assert(*f.target<int(*)()>() == g0); + } + { + typedef std::function<int(int)> Func; + Func f = g; + Func& fr = (f = f); + assert(&fr == &f); + assert(*f.target<int(*)(int)>() == g); + } + { + typedef std::function<int(int, int)> Func; + Func f = g2; + Func& fr = (f = f); + assert(&fr == &f); + assert(*f.target<int(*)(int, int)>() == g2); + } + { + typedef std::function<int(int, int, int)> Func; + Func f = g3; + Func& fr = (f = f); + assert(&fr == &f); + assert(*f.target<int(*)(int, int, int)>() == g3); + } +#if TEST_STD_VER >= 11 + assert(globalMemCounter.checkOutstandingNewEq(0)); + { std::function<int(int)> f = A(); assert(A::count == 1); assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f.target<A>()); - assert(f.target<int(*)(int)>() == 0); + assert(f.target<int (*)(int)>() == 0); std::function<int(int)> f2; f2 = std::move(f); assert(A::count == 1); assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f2.target<A>()); - assert(f2.target<int(*)(int)>() == 0); + assert(f2.target<int (*)(int)>() == 0); assert(f.target<A>() == 0); - assert(f.target<int(*)(int)>() == 0); - } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(f.target<int (*)(int)>() == 0); + } +#endif } 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 387b371a9331..9d5681a3db76 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 @@ -132,7 +132,7 @@ int main() assert(A::count == 1); assert(f2.target<A>() == nullptr); assert(f2.target<Ref>()); - assert(f.target<Ref>()); // f is unchanged because the target is small + LIBCPP_ASSERT(f.target<Ref>()); // f is unchanged because the target is small } { // Test that moving a function constructed from a function pointer @@ -146,7 +146,7 @@ int main() std::function<int(int)> f2(std::move(f)); assert(f2.target<A>() == nullptr); assert(f2.target<Ptr>()); - assert(f.target<Ptr>()); // f is unchanged because the target is small + LIBCPP_ASSERT(f.target<Ptr>()); // f is unchanged because the target is small } #endif // TEST_STD_VER >= 11 } |
