[LLVMbugs] [Bug 19118] New: Bad tuple/function interaction with -std=c++1y

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Mar 12 14:36:24 PDT 2014


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

            Bug ID: 19118
           Summary: Bad tuple/function interaction with -std=c++1y
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: howard.hinnant at gmail.com
                CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
    Classification: Unclassified

This code, compiled with -std=c++1y:

#include <tuple>
#include <functional>

struct X
{
    X();

    template <class T>
    X(T);

    void operator()() {}
};

int
main()
{
    X x;
    std::function<void()> f(x);
}

Results in a compile-time error.  It should compile.

In file included from test.cpp:1:
../libcxx/include/tuple:274:11: error: rvalue reference to type 'X' cannot bind
to lvalue of type 'X'
        : value(__t.get())
          ^     ~~~~~~~~~
../libcxx/include/type_traits:2140:63: note: in instantiation of member
function 'std::__1::__tuple_leaf<0, X &&,
      false>::__tuple_leaf' requested here
                                   && __is_constructible(_Tp, _Args...)>
                                                              ^
../libcxx/include/tuple:213:42: note: in instantiation of template class
'std::__1::is_constructible<X &&, const
      std::__1::__tuple_leaf<0, X &&, false> &>' requested here
              class = typename enable_if<is_constructible<_Hp,
_Tp>::value>::type>
                                         ^
../libcxx/include/tuple:215:18: note: in instantiation of default argument for
'__tuple_leaf<const std::__1::__tuple_leaf<0, X &&,
      false> &>' required here
        explicit __tuple_leaf(_Tp&& __t)
_NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
                 ^~~~~~~~~~~~
../libcxx/include/tuple:180:7: note: while substituting deduced template
arguments into function template '__tuple_leaf' [with _Tp
      = const std::__1::__tuple_leaf<0, X &&, false> &, $1 = <no value>]
class __tuple_leaf
      ^
../libcxx/include/tuple:501:10: note: in instantiation of template class
'std::__1::__tuple_impl<std::__1::__tuple_indices<0>, X
      &&>' requested here
    base base_;
         ^
../libcxx/include/tuple:856:1: note: in instantiation of template class
'std::__1::tuple<X &&>' requested here
forward_as_tuple(_Tp&&... __t) _NOEXCEPT
^
../libcxx/include/functional:1303:44: note: in instantiation of function
template specialization 'std::__1::forward_as_tuple<X>'
      requested here
        : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
                                           ^
../libcxx/include/functional:1596:26: note: in instantiation of member function
'std::__1::__function::__func<X,
      std::__1::allocator<X>, void ()>::__func' requested here
            ::new (__f_) _FF(_VSTD::move(__f));
                         ^
test.cpp:18:27: note: in instantiation of function template specialization
'std::__1::function<void ()>::function<X>' requested
      here
    std::function<void()> f(x);
                          ^
In file included from test.cpp:1:
../libcxx/include/tuple:275:10: error: static_assert failed "Can not copy a
tuple with rvalue reference member"
        {static_assert(!is_rvalue_reference<_Hp>::value, "Can not copy a tuple
with rvalue reference member");}
         ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.

Does not happen in -std=c++11.  This appears to be related to a subtle c++14
language change, though I haven't nailed down exactly what.  However I do have
a fix:

Index: include/tuple
===================================================================
--- include/tuple    (revision 203616)
+++ include/tuple    (working copy)
@@ -268,18 +268,9 @@
                                 >::value)),
        "Attempted to construct a reference element in a tuple with an
rvalue");}

-    _LIBCPP_INLINE_VISIBILITY
-    _LIBCPP_CONSTEXPR_AFTER_CXX11
-    __tuple_leaf(const __tuple_leaf& __t)
_NOEXCEPT_(is_nothrow_copy_constructible<_Hp>::value)
-        : value(__t.get())
-        {static_assert(!is_rvalue_reference<_Hp>::value, "Can not copy a tuple
with rvalue reference member");}
+    __tuple_leaf(const __tuple_leaf& __t) = default;
+    __tuple_leaf(__tuple_leaf&& __t) = default;

-    _LIBCPP_INLINE_VISIBILITY
-    _LIBCPP_CONSTEXPR_AFTER_CXX11
-    __tuple_leaf(__tuple_leaf&& __t)
_NOEXCEPT_(is_nothrow_move_constructible<_Hp>::value)
-        : value(_VSTD::forward<_Hp>(__t.get()))
-        {}
-
     template <class _Tp>
         _LIBCPP_INLINE_VISIBILITY
         __tuple_leaf&

With this fix, the above test compiles (passes).  Additionally the existing
tuple tests continue to pass both with -std=c++11 and -std=c++1y.  I didn't
test -std=c++03.  The libc++ <tuple> never got emulated in C++03 mode.

-- 
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/20140312/0337384e/attachment.html>


More information about the llvm-bugs mailing list