summaryrefslogtreecommitdiffstats
path: root/libcxx/include/tuple
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2015-02-21 02:30:41 +0000
committerEric Fiselier <eric@efcs.ca>2015-02-21 02:30:41 +0000
commit65500d4b29bdd03f6e3d14bd09550465bd9e16ed (patch)
treee56ee75938a9c33a4941b2a8d78758ce2f120f91 /libcxx/include/tuple
parentd2852b69ce15da37e62d98ca313febd3664c0f28 (diff)
downloadbcm5719-llvm-65500d4b29bdd03f6e3d14bd09550465bd9e16ed.tar.gz
bcm5719-llvm-65500d4b29bdd03f6e3d14bd09550465bd9e16ed.zip
[libc++] Try and prevent evaluation of `is_default_constructible` on tuples default constructor if it is not needed.
Summary: Currently parts of the SFINAE on tuples default constructor always gets evaluated even when the default constructor is never called or instantiated. This can cause a hard compile error when a tuple is created with types that do not have a default constructor. Below is a self contained example using a pair like class. This code will not compile but probably should. ``` #include <type_traits> template <class T> struct IllFormedDefaultImp { IllFormedDefaultImp(T x) : value(x) {} constexpr IllFormedDefaultImp() {} T value; }; typedef IllFormedDefaultImp<int &> IllFormedDefault; template <class T, class U> struct pair { template <bool Dummy = true, class = typename std::enable_if< std::is_default_constructible<T>::value && std::is_default_constructible<U>::value && Dummy>::type > constexpr pair() : first(), second() {} pair(T const & t, U const & u) : first(t), second(u) {} T first; U second; }; int main() { int x = 1; IllFormedDefault v(x); pair<IllFormedDefault, IllFormedDefault> p(v, v); } ``` One way to fix this is to use `Dummy` in a more involved way in the constructor SFINAE. The following patch fixes these sorts of hard compile errors for tuple. Reviewers: mclow.lists, rsmith, K-ballo, EricWF Reviewed By: EricWF Subscribers: ldionne, cfe-commits Differential Revision: http://reviews.llvm.org/D7569 llvm-svn: 230120
Diffstat (limited to 'libcxx/include/tuple')
-rw-r--r--libcxx/include/tuple4
1 files changed, 2 insertions, 2 deletions
diff --git a/libcxx/include/tuple b/libcxx/include/tuple
index 93518d8bd64..21fa900ddc3 100644
--- a/libcxx/include/tuple
+++ b/libcxx/include/tuple
@@ -511,8 +511,8 @@ class _LIBCPP_TYPE_VIS_ONLY tuple
typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
public:
- template <bool _Dummy = true, class _Up = typename enable_if<
- __all<(_Dummy && is_default_constructible<_Tp>::value)...>::value
+ template <bool _Dummy = true, class = typename enable_if<
+ __all<__dependent_type<is_default_constructible<_Tp>, _Dummy>::value...>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR tuple()
OpenPOWER on IntegriCloud