Fix libc++ bug #20039: 'Constructing std::function from empty compatible std::function results in half-empty state' Thanks to Agustin Berge for the report, and for his and Eric Fiselier's work on a fix.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@212070 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2014-06-30 21:27:51 +00:00
parent 394451db81
commit 2f9e714071
4 changed files with 46 additions and 5 deletions

View File

@@ -99,6 +99,18 @@ int main()
assert(f2.target<int(*)(int)>() == 0);
assert(f2.target<A>() == 0);
}
{
std::function<int(int)> f;
assert(new_called == 0);
assert(f.target<int(*)(int)>() == 0);
assert(f.target<A>() == 0);
assert(!f);
std::function<long(int)> g = f;
assert(new_called == 0);
assert(g.target<long(*)(int)>() == 0);
assert(g.target<A>() == 0);
assert(!g);
}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
assert(new_called == 0);
{

View File

@@ -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.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R()>
// template<class F> function(F);
#define _LIBCPP_HAS_NO_VARIADICS
#include <functional>
#include <cassert>
int main()
{
std::function<void()> f(static_cast<void(*)()>(0));
assert(!f);
}