[llvm-bugs] [Bug 25608] New: std::function consturctors use unique_ptr with incorrect template param

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Nov 22 23:09:51 PST 2015


https://llvm.org/bugs/show_bug.cgi?id=25608

            Bug ID: 25608
           Summary: std::function consturctors use unique_ptr with
                    incorrect template param
           Product: libc++
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: antoshkka at gmail.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
    Classification: Unclassified

The following constructor

template<class _Rp, class ..._ArgTypes>
template <class _Fp>
function<_Rp(_ArgTypes...)>::function(_Fp __f,
                                     typename enable_if
                                     <
                                        __callable<_Fp>::value &&
                                        !is_same<_Fp, function>::value
                                     >::type*)

Contains the following code

            typedef allocator<_FF> _Ap;
            _Ap __a;
            typedef __allocator_destructor<_Ap> _Dp;
            unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));

However type of `_FF` is not `__base`, but rather `__function::__func<_Fp,
allocator<_Fp>, _Rp(_ArgTypes...)>`. This difference leads to compilation
failures, when using libc++ with GCC compiler. Fix for that would be to replace
`unique_ptr<__base, _Dp>` with `unique_ptr<_FF, _Dp>`:

            typedef allocator<_FF> _Ap;
            _Ap __a;
            typedef __allocator_destructor<_Ap> _Dp;
            unique_ptr<__FF, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
            ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
            __f_ = (__base*)__hold.release();

Same issue could be found lower in code. Following lines:

            unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
            ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
            __f_ = __hold.release();

Must be replaced with:

            unique_ptr<__FF, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
            ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
            __f_ = (__base*)__hold.release();

-- 
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/20151123/750c035f/attachment.html>


More information about the llvm-bugs mailing list