[LLVMbugs] [Bug 21917] New: Error in std::pair default constructor when elements are not default-constructible
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Mon Dec 15 10:17:01 PST 2014
http://llvm.org/bugs/show_bug.cgi?id=21917
Bug ID: 21917
Summary: Error in std::pair default constructor when elements
are not default-constructible
Product: libc++
Version: 3.4
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: eniebler at boost.org
CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
Classification: Unclassified
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)
{}
};
-------------------------------------------
--
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/20141215/84427804/attachment.html>
More information about the llvm-bugs
mailing list