Address @K-ballo's comments.
http://reviews.llvm.org/D7569
Files:
include/tuple
include/type_traits
test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp
Index: include/tuple
===================================================================
--- include/tuple
+++ include/tuple
@@ -511,8 +511,8 @@
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()
Index: include/type_traits
===================================================================
--- include/type_traits
+++ include/type_traits
@@ -216,6 +216,9 @@
struct __void_t { typedef void type; };
#endif
+template <class _Tp, bool>
+struct _LIBCPP_TYPE_VIS_ONLY __dependent_type : public _Tp {};
+
template <bool _Bp, class _If, class _Then>
struct _LIBCPP_TYPE_VIS_ONLY conditional {typedef _If type;};
template <class _If, class _Then>
Index: test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp
===================================================================
--- test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp
+++ test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp
@@ -35,6 +35,16 @@
ThrowingDefault() { }
};
+struct IllFormedDefault {
+ IllFormedDefault(int x) : value(x) {}
+ template <bool Pred = false>
+ constexpr IllFormedDefault() {
+ static_assert(Pred,
+ "The default constructor should not be instantiated");
+ }
+ int value;
+};
+
int main()
{
{
@@ -89,5 +99,12 @@
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == nullptr);
}
+ {
+ // Check that the SFINAE on the default constructor is not evaluted when
+ // it isn't needed. If the default constructor is evaluted then this test
+ // should fail to compile.
+ IllFormedDefault v(0);
+ std::tuple<IllFormedDefault> t(v);
+ }
#endif
}
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
Index: include/tuple
===================================================================
--- include/tuple
+++ include/tuple
@@ -511,8 +511,8 @@
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()
Index: include/type_traits
===================================================================
--- include/type_traits
+++ include/type_traits
@@ -216,6 +216,9 @@
struct __void_t { typedef void type; };
#endif
+template <class _Tp, bool>
+struct _LIBCPP_TYPE_VIS_ONLY __dependent_type : public _Tp {};
+
template <bool _Bp, class _If, class _Then>
struct _LIBCPP_TYPE_VIS_ONLY conditional {typedef _If type;};
template <class _If, class _Then>
Index: test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp
===================================================================
--- test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp
+++ test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp
@@ -35,6 +35,16 @@
ThrowingDefault() { }
};
+struct IllFormedDefault {
+ IllFormedDefault(int x) : value(x) {}
+ template <bool Pred = false>
+ constexpr IllFormedDefault() {
+ static_assert(Pred,
+ "The default constructor should not be instantiated");
+ }
+ int value;
+};
+
int main()
{
{
@@ -89,5 +99,12 @@
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == nullptr);
}
+ {
+ // Check that the SFINAE on the default constructor is not evaluted when
+ // it isn't needed. If the default constructor is evaluted then this test
+ // should fail to compile.
+ IllFormedDefault v(0);
+ std::tuple<IllFormedDefault> t(v);
+ }
#endif
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits