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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to