[LLVMbugs] [Bug 19473] New: std::function fails to compile with non-default-constructible custom allocators

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Apr 17 18:13:17 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=19473

            Bug ID: 19473
           Summary: std::function fails to compile with
                    non-default-constructible custom allocators
           Product: libc++
           Version: 3.3
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: applmak at google.com
                CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
    Classification: Unclassified

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140418/c0202314/attachment.html>


More information about the llvm-bugs mailing list