forked from OSchip/llvm-project
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
|
||
|---|---|---|
| .. | ||
| UTypes.fail.cpp | ||
| UTypes.pass.cpp | ||
| alloc.pass.cpp | ||
| alloc_UTypes.pass.cpp | ||
| alloc_const_Types.pass.cpp | ||
| alloc_const_pair.pass.cpp | ||
| alloc_convert_copy.pass.cpp | ||
| alloc_convert_move.pass.cpp | ||
| alloc_copy.pass.cpp | ||
| alloc_move.pass.cpp | ||
| alloc_move_pair.pass.cpp | ||
| const_Types.fail.cpp | ||
| const_Types.pass.cpp | ||
| const_Types2.fail.cpp | ||
| const_pair.pass.cpp | ||
| convert_copy.pass.cpp | ||
| convert_move.pass.cpp | ||
| copy.fail.cpp | ||
| copy.pass.cpp | ||
| default.pass.cpp | ||
| move.pass.cpp | ||
| move_pair.pass.cpp | ||
| tuple_array_template_depth.pass.cpp | ||