<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - std::function fails to compile with non-default-constructible custom allocators"
href="http://llvm.org/bugs/show_bug.cgi?id=19473">19473</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>std::function fails to compile with non-default-constructible custom allocators
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>3.3
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>applmak@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu, mclow.lists@gmail.com
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>I have a custom allocator that takes a single param in its constructor:
explicit FunctionAllocator(CircularAllocator& backing_store)
: backing_store_(backing_store) {}
Then a use of std::function:
CircularAllocator backing_store;
FunctionAllocator<std::function<void()>> fa(backing_store);
std::function<void()> f(std::allocator_arg, fa,
[]{ std::cerr << "EXEC: No bound vars." << std::endl; });
f();
But in my xcode using clang/llvm/libc++, the definition of f doesn't compile,
because of this:
...
typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
if (sizeof(_FF) <= sizeof(__buf_) &&
is_nothrow_copy_constructible<_Fp>::value)
{
__f_ = (__base*)&__buf_;
::new (__f_) _FF(_VSTD::move(__f)); // Here is where the compile
is failing.
}
else
...
This is the fast-path mode of std::function that is intended to avoid a heap
allocation from the lambda's closed-over vars to the std::function's. I love
this assignment for a lot of reasons, but the problem here is that it calls the
move constructor of _FF which doesn't take an allocator instance. Since the
allocator is mentioned in the type of _FF, it attempts to default-construct a
FunctionAllocator, which fails because FunctionAllocator has no default
constructor.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>