[cfe-dev] Broken type deduction for pair of reference_wrappers?

Michael Price michael.b.price.dev at gmail.com
Wed Aug 8 19:41:12 PDT 2012


Given two objects, one and two that are references to some pure virtual
type MyType, the following code compiles fine:

    std::pair<std::reference_wrapper<MyType>,std::reference_wrapper<
MyType >> mypair = std::make_pair(std::ref(one), std::ref(two));
    std::swap(mypair.first, mypair.second);

But if I replace the declaration of the pair object type with 'auto' as in:

    auto mypair = std::make_pair(std::ref(one), std::ref(two));

I get the following errors with std::swap:

GameController.cpp:43:9: error: no matching function for call to 'swap'
        std::swap(mypair.first, mypair.second);
        ^~~~~~~~~
/usr/include/c++/v1/type_traits:2902:5: note: candidate template ignored:
disabled by 'enable_if' [with _Tp = MyType]
    is_move_constructible<_Tp>::value &&
    ^
/usr/include/c++/v1/utility:185:1: note: candidate template ignored: failed
template argument deduction
swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np])
_NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
^
/usr/include/c++/v1/utility:412:1: note: candidate template ignored: failed
template argument deduction
swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
^
/usr/include/c++/v1/tuple:220:6: note: candidate template ignored: failed
template argument deduction
void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>&
__y)
     ^
/usr/include/c++/v1/tuple:751:1: note: candidate template ignored: failed
template argument deduction
swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
^
/usr/include/c++/v1/memory:2440:1: note: candidate template ignored: failed
template argument deduction
swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
^
/usr/include/c++/v1/memory:2928:1: note: candidate template ignored: failed
template argument deduction
swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT
{__x.swap(__y);}
^
/usr/include/c++/v1/memory:4862:1: note: candidate template ignored: failed
template argument deduction
swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
^
/usr/include/c++/v1/memory:5151:1: note: candidate template ignored: failed
template argument deduction
swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
^
/usr/include/c++/v1/array:279:1: note: candidate template ignored: failed
template argument deduction
swap(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
^
/usr/include/c++/v1/__bit_reference:86:1: note: candidate template ignored:
failed template argument deduction
swap(__bit_reference<_Cp> __x, __bit_reference<_Dp> __y) _NOEXCEPT
^
/usr/include/c++/v1/__bit_reference:96:1: note: candidate template ignored:
failed template argument deduction
swap(__bit_reference<_Cp> __x, bool& __y) _NOEXCEPT
^
/usr/include/c++/v1/__bit_reference:106:1: note: candidate template
ignored: failed template argument deduction
swap(bool& __x, __bit_reference<_Cp> __y) _NOEXCEPT
^
/usr/include/c++/v1/__split_buffer:644:1: note: candidate template ignored:
failed template argument deduction
swap(__split_buffer<_Tp, _Allocator>& __x, __split_buffer<_Tp, _Allocator>&
__y)
^
/usr/include/c++/v1/vector:3163:1: note: candidate template ignored: failed
template argument deduction
swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
^
/usr/include/c++/v1/functional:1492:1: note: candidate template ignored:
failed template argument deduction
swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y)
_NOEXCEPT
^

Is this a bug?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120808/8b9ca188/attachment.html>


More information about the cfe-dev mailing list