Author: ericwf Date: Wed Mar 18 17:56:50 2015 New Revision: 232686 URL: http://llvm.org/viewvc/llvm-project?rev=232686&view=rev Log: [libc++] Fix PR22922 - Allocator support for std::function does not know how to rebind.
Summary: This patch changes std::function to use allocator_traits to rebind the allocator instead of allocator itself. It also changes most of the tests to use `bare_allocator` where possible instead of `test_allocator`. Reviewers: mclow.lists Reviewed By: mclow.lists Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D8391 Modified: libcxx/trunk/include/functional libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp Modified: libcxx/trunk/include/functional URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/functional?rev=232686&r1=232685&r2=232686&view=diff ============================================================================== --- libcxx/trunk/include/functional (original) +++ libcxx/trunk/include/functional Wed Mar 18 17:56:50 2015 @@ -1367,7 +1367,14 @@ template<class _Fp, class _Alloc, class __base<_Rp(_ArgTypes...)>* __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const { - typedef typename _Alloc::template rebind<__func>::other _Ap; + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __alloc_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<__func> +#else + rebind_alloc<__func>::other +#endif + _Ap; _Ap __a(__f_.second()); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); @@ -1393,7 +1400,14 @@ template<class _Fp, class _Alloc, class void __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT { - typedef typename _Alloc::template rebind<__func>::other _Ap; + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __alloc_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<__func> +#else + rebind_alloc<__func>::other +#endif + _Ap; _Ap __a(__f_.second()); __f_.~__compressed_pair<_Fp, _Alloc>(); __a.deallocate(this, 1); Modified: libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp?rev=232686&r1=232685&r2=232686&view=diff ============================================================================== --- libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp (original) +++ libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp Wed Mar 18 17:56:50 2015 @@ -16,10 +16,12 @@ #include <functional> #include <cassert> -#include "test_allocator.h" +#include "min_allocator.h" int main() { - std::function<int(int)> f(std::allocator_arg, test_allocator<int>()); + { + std::function<int(int)> f(std::allocator_arg, bare_allocator<int>()); assert(!f); + } } Modified: libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp?rev=232686&r1=232685&r2=232686&view=diff ============================================================================== --- libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp (original) +++ libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp Wed Mar 18 17:56:50 2015 @@ -16,7 +16,7 @@ #include <functional> #include <cassert> -#include "test_allocator.h" +#include "min_allocator.h" class A { @@ -57,19 +57,19 @@ public: int main() { { - std::function<int(int)> f(std::allocator_arg, test_allocator<A>(), A()); + std::function<int(int)> f(std::allocator_arg, bare_allocator<A>(), A()); assert(A::count == 1); assert(f.target<A>()); assert(f.target<int(*)(int)>() == 0); } assert(A::count == 0); { - std::function<int(int)> f(std::allocator_arg, test_allocator<int(*)(int)>(), g); + std::function<int(int)> f(std::allocator_arg, bare_allocator<int(*)(int)>(), g); assert(f.target<int(*)(int)>()); assert(f.target<A>() == 0); } { - std::function<int(int)> f(std::allocator_arg, test_allocator<int(*)(int)>(), + std::function<int(int)> f(std::allocator_arg, bare_allocator<int(*)(int)>(), (int (*)(int))0); assert(!f); assert(f.target<int(*)(int)>() == 0); @@ -77,7 +77,7 @@ int main() } { std::function<int(const A*, int)> f(std::allocator_arg, - test_allocator<int(A::*)(int)const>(), + bare_allocator<int(A::*)(int)const>(), &A::foo); assert(f); assert(f.target<int (A::*)(int) const>() != 0); @@ -91,7 +91,7 @@ int main() #endif { std::function<void(int)> fun(std::allocator_arg, - test_allocator<int(*)(int)>(), + bare_allocator<int(*)(int)>(), &g); assert(fun); assert(fun.target<int(*)(int)>() != 0); Modified: libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp?rev=232686&r1=232685&r2=232686&view=diff ============================================================================== --- libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp (original) +++ libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp Wed Mar 18 17:56:50 2015 @@ -17,6 +17,7 @@ #include <functional> #include <cassert> +#include "min_allocator.h" #include "test_allocator.h" #include "count_new.hpp" @@ -58,7 +59,7 @@ int main() assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f.target<A>()); assert(f.target<int(*)(int)>() == 0); - std::function<int(int)> f2(std::allocator_arg, test_allocator<A>(), f); + std::function<int(int)> f2(std::allocator_arg, bare_allocator<A>(), f); assert(A::count == 2); assert(globalMemCounter.checkOutstandingNewEq(2)); assert(f2.target<A>()); @@ -71,7 +72,7 @@ int main() assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target<int(*)(int)>()); assert(f.target<A>() == 0); - std::function<int(int)> f2(std::allocator_arg, test_allocator<int(*)(int)>(), f); + std::function<int(int)> f2(std::allocator_arg, bare_allocator<int(*)(int)>(), f); assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f2.target<int(*)(int)>()); assert(f2.target<A>() == 0); @@ -91,7 +92,7 @@ int main() assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target<int(*)(int)>() == 0); assert(f.target<A>() == 0); - std::function<int(int)> f2(std::allocator_arg, test_allocator<int>(), f); + std::function<int(int)> f2(std::allocator_arg, bare_allocator<int>(), f); assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f2.target<int(*)(int)>() == 0); assert(f2.target<A>() == 0); Modified: libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp?rev=232686&r1=232685&r2=232686&view=diff ============================================================================== --- libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp (original) +++ libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp Wed Mar 18 17:56:50 2015 @@ -16,10 +16,10 @@ #include <functional> #include <cassert> -#include "test_allocator.h" +#include "min_allocator.h" int main() { - std::function<int(int)> f(std::allocator_arg, test_allocator<int>(), nullptr); + std::function<int(int)> f(std::allocator_arg, bare_allocator<int>(), nullptr); assert(!f); } Modified: libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp?rev=232686&r1=232685&r2=232686&view=diff ============================================================================== --- libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp (original) +++ libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp Wed Mar 18 17:56:50 2015 @@ -16,7 +16,7 @@ #include <functional> #include <cassert> -#include "test_allocator.h" +#include "min_allocator.h" #include "count_new.hpp" class A @@ -56,7 +56,7 @@ int main() assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f.target<A>()); assert(f.target<int(*)(int)>() == 0); - std::function<int(int)> f2(std::allocator_arg, test_allocator<A>(), std::move(f)); + std::function<int(int)> f2(std::allocator_arg, bare_allocator<A>(), std::move(f)); assert(A::count == 1); assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f2.target<A>()); _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
