[PATCH] Proposed change to the constructor of std::pair
Eric Fiselier
eric at efcs.ca
Wed Feb 11 15:00:43 PST 2015
The code as it currently stands now will fail to compile the following code (that currently works).
#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
{
#if defined(USE_SFINAE)
template <bool Dummy = true,
class = typename std::enable_if<
std::is_default_constructible<T>::value
&& std::is_default_constructible<U>::value
&& Dummy>::type
>
#endif
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);
}
`clang++ -std=c++11 test.cpp` compiles just fine.
`clang++ -std=c++11 -DUSE_SFINAE test.cpp` fails to compile.
You can work around this by using something like this
template <class T, bool>
struct dependent_is_default_constructible : std::is_default_constructible<T> {};
http://reviews.llvm.org/D7384
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the cfe-commits
mailing list