From: Eric Fiselier Date: Sat, 13 Jun 2015 08:25:24 +0000 (+0000) Subject: Cleanup result_of tests and fix issues with the C++03 result_of. X-Git-Tag: llvmorg-3.7.0-rc1~2429 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d9ad0cbd70426f1b85d37d9059e66b2e5f1f0c8b;p=platform%2Fupstream%2Fllvm.git Cleanup result_of tests and fix issues with the C++03 result_of. The two main fixes this patch contains are: - use __identity_t instead of common_type. common_type was used as an identity metafunction but the decay resulted in incorrect results. - Pointers to free functions were not counted as functions. Remove the pointer before checking if a type is a function. llvm-svn: 239668 --- diff --git a/libcxx/TODO.TXT b/libcxx/TODO.TXT index e2ad333..513b863 100644 --- a/libcxx/TODO.TXT +++ b/libcxx/TODO.TXT @@ -38,8 +38,6 @@ Misc Tasks ========== * Find all sequences of >2 underscores and eradicate them. * run clang-tidy on libc++ -* Look at test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp; - why are the tests duplicated? * Document the "conditionally-supported" bits of libc++ * Look at basic_string's move assignment operator, re LWG 2063 and POCMA * libc++ is missing try_emplace diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits index 5965b79..3c773ba 100644 --- a/libcxx/include/type_traits +++ b/libcxx/include/type_traits @@ -219,6 +219,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD template struct __void_t { typedef void type; }; +template +struct __identity { typedef T type; }; + template struct _LIBCPP_TYPE_VIS_ONLY __dependent_type : public _Tp {}; @@ -2252,7 +2255,7 @@ struct __result_of_mp; template struct __result_of_mp<_MP, _Tp, true> - : public common_type::_ReturnType> + : public __identity::_ReturnType> { }; @@ -2320,7 +2323,7 @@ template class _LIBCPP_TYPE_VIS_ONLY result_of<_Fn()> : public __result_of<_Fn(), is_class::type>::value || - is_function::type>::value, + is_function::type>::type>::value, is_member_pointer::type>::value > { @@ -2330,7 +2333,7 @@ template class _LIBCPP_TYPE_VIS_ONLY result_of<_Fn(_A0)> : public __result_of<_Fn(_A0), is_class::type>::value || - is_function::type>::value, + is_function::type>::type>::value, is_member_pointer::type>::value > { @@ -2340,7 +2343,7 @@ template class _LIBCPP_TYPE_VIS_ONLY result_of<_Fn(_A0, _A1)> : public __result_of<_Fn(_A0, _A1), is_class::type>::value || - is_function::type>::value, + is_function::type>::type>::value, is_member_pointer::type>::value > { @@ -2350,7 +2353,7 @@ template class _LIBCPP_TYPE_VIS_ONLY result_of<_Fn(_A0, _A1, _A2)> : public __result_of<_Fn(_A0, _A1, _A2), is_class::type>::value || - is_function::type>::value, + is_function::type>::type>::value, is_member_pointer::type>::value > { diff --git a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp index 1064d59..5a925bb3 100644 --- a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp +++ b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp @@ -13,83 +13,240 @@ #include #include - -typedef bool (&PF1)(); -typedef short (*PF2)(long); +#include "test_macros.h" struct S { - operator PF2() const; + typedef short (*FreeFunc)(long); + operator FreeFunc() const; double operator()(char, int&); - void calc(long) const; - char data_; + double const& operator()(char, int&) const; + double volatile& operator()(char, int&) volatile; + double const volatile& operator()(char, int&) const volatile; }; -typedef void (S::*PMS)(long) const; -typedef char S::*PMD; - -struct wat -{ - wat& operator*() { return *this; } - void foo(); +template +struct Voider { + typedef void type; }; -struct F {}; +template +struct HasType : std::false_type {}; + +template +struct HasType::type> : std::true_type {}; template -void test_result_of_imp() +void test_result_of() { static_assert((std::is_same::type, U>::value), ""); -#if _LIBCPP_STD_VER > 11 - static_assert((std::is_same, U>::value), ""); +} + +template +void test_no_result() +{ +#if TEST_STD_VER >= 11 + static_assert((!HasType >::value), ""); #endif } int main() { - test_result_of_imp (); - test_result_of_imp (); - test_result_of_imp (); - test_result_of_imp, int), void> (); - test_result_of_imp (); - test_result_of_imp (); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - test_result_of_imp (); -#endif - test_result_of_imp (); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - test_result_of_imp (); - test_result_of_imp (); - test_result_of_imp (); - test_result_of_imp (); - test_result_of_imp (); - test_result_of_imp (); -#endif -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - using type1 = std::result_of::type; - static_assert(std::is_same::value, ""); -#endif -#if _LIBCPP_STD_VER > 11 - using type2 = std::result_of_t; - static_assert(std::is_same::value, ""); -#endif + { // functor object + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + } + { // pointer to function + typedef bool (&RF0)(); + typedef bool* (&RF1)(int); + typedef bool& (&RF2)(int, int); + typedef bool const& (&RF3)(int, int, int); + typedef bool (*PF0)(); + typedef bool* (*PF1)(int); + typedef bool& (*PF2)(int, int); + typedef bool const& (*PF3)(int, int, int); + typedef bool (*&PRF0)(); + typedef bool* (*&PRF1)(int); + typedef bool& (*&PRF2)(int, int); + typedef bool const& (*&PRF3)(int, int, int); + test_result_of(); + test_result_of(); + test_result_of(); + test_result_of(); + test_result_of(); + test_result_of(); + test_result_of(); + test_result_of(); + test_result_of(); + test_result_of(); + test_result_of(); + test_result_of(); + } + { // pointer to member function - static_assert((std::is_same::type, short>::value), "Error!"); - static_assert((std::is_same::type, double>::value), "Error!"); - static_assert((std::is_same::type, bool>::value), "Error!"); - static_assert((std::is_same, int)>::type, void>::value), "Error!"); - static_assert((std::is_same::type, void>::value), "Error!"); - static_assert((std::is_same::type, void>::value), "Error!"); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - static_assert((std::is_same::type, char&&>::value), "Error!"); -#endif - static_assert((std::is_same::type, const char&>::value), "Error!"); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - static_assert((std::is_same::type, int>::value), "Error!"); - static_assert((std::is_same::type, int>::value), "Error!"); - static_assert((std::is_same::type, int>::value), "Error!"); - static_assert((std::is_same::type, int>::value), "Error!"); - static_assert((std::is_same::type, int>::value), "Error!"); - static_assert((std::is_same::type, int>::value), "Error!"); -#endif + typedef int (S::*PMS0)(); + typedef int* (S::*PMS1)(long); + typedef int& (S::*PMS2)(long, int); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of), int> (); + test_no_result(); + test_no_result(); + test_no_result(); + + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of, int), int*> (); + test_no_result(); + test_no_result(); + test_no_result(); + + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of, int, int), int&> (); + test_no_result(); + test_no_result(); + test_no_result(); + + typedef int (S::*PMS0C)() const; + typedef int* (S::*PMS1C)(long) const; + typedef int& (S::*PMS2C)(long, int) const; + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of), int> (); + test_no_result(); + test_no_result(); + + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of, int), int*> (); + test_no_result(); + test_no_result(); + + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of, int, int), int&> (); + test_no_result(); + test_no_result(); + + typedef int (S::*PMS0V)() volatile; + typedef int* (S::*PMS1V)(long) volatile; + typedef int& (S::*PMS2V)(long, int) volatile; + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of), int> (); + test_no_result(); + test_no_result(); + + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of, int), int*> (); + test_no_result(); + test_no_result(); + + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of, int, int), int&> (); + test_no_result(); + test_no_result(); + + typedef int (S::*PMS0CV)() const volatile; + typedef int* (S::*PMS1CV)(long) const volatile; + typedef int& (S::*PMS2CV)(long, int) const volatile; + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of), int> (); + + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of, int), int*> (); + + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of, int, int), int&> (); + } + { // pointer to member data + typedef char S::*PMD; + test_result_of(); + test_result_of(); + test_result_of(); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + test_result_of (); + } } diff --git a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp new file mode 100644 index 0000000..6996cdd --- /dev/null +++ b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: c++98, c++03 +// +// +// +// result_of + +#include +#include "test_macros.h" + +struct wat +{ + wat& operator*() { return *this; } + void foo(); +}; + +struct F {}; + +template +void test_result_of_imp() +{ + static_assert((std::is_same::type, U>::value), ""); +#if TEST_STD_VER > 11 + static_assert((std::is_same, U>::value), ""); +#endif +} + +int main() +{ + { + typedef char F::*PMD; + test_result_of_imp(); + test_result_of_imp(); + test_result_of_imp(); + test_result_of_imp(); + + test_result_of_imp(); + test_result_of_imp(); + test_result_of_imp(); + test_result_of_imp(); + + test_result_of_imp(); + test_result_of_imp(); + test_result_of_imp(); + test_result_of_imp(); + } + { + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + test_result_of_imp (); + } + + test_result_of_imp(); +}