[PATCH] Proposed change to the constructor of std::pair
Marshall Clow
mclow.lists at gmail.com
Tue Feb 3 11:11:11 PST 2015
Hi EricWF, howard.hinnant,
Eric Niebler proposed this as a fix for http://llvm.org/bugs/show_bug.cgi?id=21917.
I've tested it, and found that it does solve the problem in the PR.
Note that this is (probably) a defect in the standard, and that this would be an extension.
My concern is to make sure that this is (a) a conforming extension, and (b) not an ABI change.
The standard says that the default constructor for pair requires that both types be default-constructible.
I don't have tests for this (yet), but the program in the bug now compiles w/o error.
http://reviews.llvm.org/D7384
Files:
include/utility
Index: include/utility
===================================================================
--- include/utility
+++ include/utility
@@ -260,7 +260,14 @@
// pair(const pair&) = default;
// pair(pair&&) = default;
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() : first(), second() {}
+ template<bool __b = true,
+ typename = typename enable_if<
+ std::is_default_constructible<_T1>::value
+ && std::is_default_constructible<_T2>::value
+ && __b>::type
+ >
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+ pair() : first(), second() {}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pair(const _T1& __x, const _T2& __y)
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7384.19248.patch
Type: text/x-patch
Size: 717 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150203/3cb1efa2/attachment.bin>
More information about the cfe-commits
mailing list