diff options
| author | Eric Fiselier <eric@efcs.ca> | 2015-09-08 00:13:57 +0000 |
|---|---|---|
| committer | Eric Fiselier <eric@efcs.ca> | 2015-09-08 00:13:57 +0000 |
| commit | 21dfbfb426aa443a5538960a74aaf1b3bf0358c1 (patch) | |
| tree | e8279627a27f1c9ecd40922d9e1cd1758ac63212 /libcxx/test/std/utilities/meta | |
| parent | bb9a6ccfa83ef879c612bc352e2af5e6e6bf2a56 (diff) | |
| download | bcm5719-llvm-21dfbfb426aa443a5538960a74aaf1b3bf0358c1.tar.gz bcm5719-llvm-21dfbfb426aa443a5538960a74aaf1b3bf0358c1.zip | |
make common_type SFINAE-friendly and support void. Patch from Agustin Berge.
This patch also fixes PR22135. (https://llvm.org/bugs/show_bug.cgi?id=22135)
See the review for more information: http://reviews.llvm.org/D6964
llvm-svn: 246977
Diffstat (limited to 'libcxx/test/std/utilities/meta')
| -rw-r--r-- | libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp | 58 |
1 files changed, 54 insertions, 4 deletions
diff --git a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp index 91bf7e7654e..e8611253c5d 100644 --- a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp +++ b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp @@ -13,11 +13,39 @@ #include <type_traits> +#include "test_macros.h" + +struct E {}; + +template <class T> +struct X { explicit X(T const&){} }; + +template <class T> +struct S { explicit S(T const&){} }; + +namespace std +{ + template <typename T> + struct common_type<T, ::S<T> > + { + typedef S<T> type; + }; +} + +#if TEST_STD_VER >= 11 +template <class T, class U, class = void> +struct no_common_type : std::true_type {}; + +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() { static_assert((std::is_same<std::common_type<int>::type, int>::value), ""); static_assert((std::is_same<std::common_type<char>::type, char>::value), ""); -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 static_assert((std::is_same<std::common_type_t<int>, int>::value), ""); static_assert((std::is_same<std::common_type_t<char>, char>::value), ""); #endif @@ -29,7 +57,7 @@ int main() static_assert((std::is_same<std::common_type<int, int>::type, int>::value), ""); static_assert((std::is_same<std::common_type<int, const int>::type, int>::value), ""); - + static_assert((std::is_same<std::common_type<long, const int>::type, long>::value), ""); static_assert((std::is_same<std::common_type<const long, int>::type, long>::value), ""); static_assert((std::is_same<std::common_type<long, volatile int>::type, long>::value), ""); @@ -38,15 +66,37 @@ int main() static_assert((std::is_same<std::common_type<double, char>::type, double>::value), ""); static_assert((std::is_same<std::common_type<short, char>::type, int>::value), ""); -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 static_assert((std::is_same<std::common_type_t<double, char>, double>::value), ""); static_assert((std::is_same<std::common_type_t<short, char>, int>::value), ""); #endif static_assert((std::is_same<std::common_type<double, char, long long>::type, double>::value), ""); static_assert((std::is_same<std::common_type<unsigned, char, long long>::type, long long>::value), ""); -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 static_assert((std::is_same<std::common_type_t<double, char, long long>, double>::value), ""); static_assert((std::is_same<std::common_type_t<unsigned, char, long long>, long long>::value), ""); #endif + + static_assert((std::is_same<std::common_type< void>::type, void>::value), ""); + static_assert((std::is_same<std::common_type<const void>::type, void>::value), ""); + static_assert((std::is_same<std::common_type< volatile void>::type, void>::value), ""); + static_assert((std::is_same<std::common_type<const volatile void>::type, void>::value), ""); + + static_assert((std::is_same<std::common_type<void, const void>::type, void>::value), ""); + static_assert((std::is_same<std::common_type<const void, void>::type, void>::value), ""); + static_assert((std::is_same<std::common_type<void, volatile void>::type, void>::value), ""); + static_assert((std::is_same<std::common_type<volatile void, void>::type, void>::value), ""); + static_assert((std::is_same<std::common_type<const void, const void>::type, void>::value), ""); + +#if TEST_STD_VER >= 11 + 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, X<int> >::value), ""); +#endif // TEST_STD_VER >= 11 + + static_assert((std::is_same<std::common_type<int, S<int> >::type, S<int> >::value), ""); + static_assert((std::is_same<std::common_type<int, S<int>, S<int> >::type, S<int> >::value), ""); + static_assert((std::is_same<std::common_type<int, int, S<int> >::type, S<int> >::value), ""); } |

