<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Bad tuple/function interaction with -std=c++1y"
   href="http://llvm.org/bugs/show_bug.cgi?id=19118">19118</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Bad tuple/function interaction with -std=c++1y
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>howard.hinnant@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu, mclow.lists@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>