Fix PR31481 - 3+ parameter common_type isn't SFINAE friendly

llvm-svn: 290624
This commit is contained in:
Eric Fiselier 2016-12-27 19:59:50 +00:00
parent e60b294be8
commit b6d0b83cd2
2 changed files with 28 additions and 8 deletions

View File

@ -2020,13 +2020,21 @@ template <class ...Tp> struct __common_types;
template <class, class = void>
struct __common_type_impl {};
template <class _Tp, class _Up>
struct __common_type_impl<
__common_types<_Tp, _Up>,
typename __void_t<typename common_type<_Tp, _Up>::type>::type>
{
typedef typename common_type<_Tp, _Up>::type type;
};
template <class _Tp, class _Up, class ..._Vp>
struct __common_type_impl<__common_types<_Tp, _Up, _Vp...>,
typename __void_t<typename common_type<_Tp, _Up>::type>::type>
: __common_type_impl<
__common_types<typename common_type<_Tp, _Up>::type, _Vp...> >
{
typedef typename common_type<
typename common_type<_Tp, _Up>::type, _Vp...
>::type type;
};
template <class _Tp, class _Up, class ..._Vp>

View File

@ -33,12 +33,21 @@ namespace std
}
#if TEST_STD_VER >= 11
template <class T, class U, class = void>
struct no_common_type : std::true_type {};
template <class Tp>
struct always_bool_imp { using type = bool; };
template <class Tp> using always_bool = typename always_bool_imp<Tp>::type;
template <class ...Args>
constexpr auto no_common_type_imp(int)
-> always_bool<typename std::common_type<Args...>::type>
{ return false; }
template <class ...Args>
constexpr bool no_common_type_imp(long) { return true; }
template <class ...Args>
using no_common_type = std::integral_constant<bool, no_common_type_imp<Args...>(0)>;
template <class T, class U>
struct no_common_type<T, U, typename std::conditional<false,
typename std::common_type<T, U>::type, void>::type> : std::false_type {};
#endif // TEST_STD_VER >= 11
int main()
@ -93,6 +102,9 @@ int main()
static_assert((no_common_type<void, int>::value), "");
static_assert((no_common_type<int, void>::value), "");
static_assert((no_common_type<int, E>::value), "");
static_assert((no_common_type<int, int, E>::value), "");
static_assert((no_common_type<int, int, E, int>::value), "");
static_assert((no_common_type<int, int, int, E>::value), "");
static_assert((no_common_type<int, X<int> >::value), "");
#endif // TEST_STD_VER >= 11