<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 --- - Error in std::pair default constructor when elements are not default-constructible"
href="http://llvm.org/bugs/show_bug.cgi?id=21917">21917</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Error in std::pair default constructor when elements are not default-constructible
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>3.4
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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>eniebler@boost.org
</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>The following trivial code causes a hard error:
-------------------------------------
#include <utility>
#include <tuple>
int main()
{
int i=0,j=0;
std::make_tuple(std::make_pair(std::ref(i),std::ref(j)));
}
-------------------------------------
The error is:
-------------------------------------
/usr/include/c++/v1/utility:259:58: error: reference to type 'int' requires an
initializer
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() : first(), second() {}
^
/usr/include/c++/v1/type_traits:2342:38: note: in instantiation of member
function
'std::__1::pair<int &, int &>::pair' requested here
: public integral_constant<bool, __is_constructible(_Tp, _Args...)>
^
/usr/include/c++/v1/type_traits:2646:14: note: in instantiation of template
class
'std::__1::is_constructible<std::__1::pair<int &, int &>>' requested here
: public is_constructible<_Tp>
^
/usr/include/c++/v1/tuple:515:26: note: in instantiation of template class
'std::__1::is_default_constructible<std::__1::pair<int &, int &> >'
requested here
__all<(_Dummy && is_default_constructible<_Tp>::value)...>::value
^
/home/eric/libcxx-test/test.cpp:7:5: note: in instantiation of template class
'std::__1::tuple<std::__1::pair<int &, int &> >' requested here
std::make_tuple(std::make_pair(std::ref(i),std::ref(j)));
^
In file included from /home/eric/libcxx-test/test.cpp:1:
/usr/include/c++/v1/utility:259:67: error: reference to type 'int' requires an
initializer
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() : first(), second() {}
^
2 errors generated.
-------------------------------------
Tuple is asking pair if it is default-constructible (I'm unsure why), and just
asking is triggering the error because pair is *not* default-constructible. But
the default constructor exists anyway.
This is most certainly a std defect, but IMO libc++ should be proactive and
SFINAE's pair's default constructor if _T1 and _T2 are not
default-constructible. (Defining it =default would be a behavior change because
it wouldn't value-initialize it's members when the pair is
default-initialized.)
Here is a simple struct that shows how the pair default constructor could be
defined:
-------------------------------------------
template<typename T1, typename T2>
struct my_pair
{
T1 first;
T2 second;
template<
bool B = true,
typename = typename std::enable_if<
std::is_default_constructible<T1>::value &&
std::is_default_constructible<T2>::value &&
B
>::type
>
my_pair() :first(), second()
{}
my_pair(const T1& f, const T2& s)
:first(f), second(s)
{}
};
-------------------------------------------</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>