From 4bd15469a95f4400ebe7b8ff7ef9ac53e18eecd4 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Mon, 30 Mar 2015 15:22:20 +0000 Subject: [PATCH] [libcxx] Fix PR22771 - Support access control SFINAE in the library version of is_convertible. Summary: Currently the conversion check does not take place in a context where access control SFINAE is applied. This patch changes the context of the test expression so that SFINAE occurs if access control does not permit the conversion. Related bug: https://llvm.org/bugs/show_bug.cgi?id=22771 Reviewers: mclow.lists, rsmith, dim Reviewed By: dim Subscribers: dim, rodrigc, emaste, cfe-commits Differential Revision: http://reviews.llvm.org/D8461 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@233552 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/type_traits | 17 ++++++++++++----- .../meta/meta.rel/is_convertible.pass.cpp | 6 ++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/type_traits b/include/type_traits index 184926a50..aad942565 100644 --- a/include/type_traits +++ b/include/type_traits @@ -848,7 +848,16 @@ template struct _LIBCPP_TYPE_VIS_ONLY is_convertible namespace __is_convertible_imp { -template char __test(_Tp); +template void __test_convert(_Tp); + +template +struct __is_convertible_test : public false_type {}; + +template +struct __is_convertible_test<_From, _To, + decltype(__test_convert<_To>(_VSTD::declval<_From>()))> : public true_type +{}; + template __two __test(...); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template _Tp&& __source(); @@ -883,10 +892,8 @@ template ::value> struct __is_convertible : public integral_constant(__is_convertible_imp::__source<_T1>())) == 1 -#else - sizeof(__is_convertible_imp::__test<_T2>(__is_convertible_imp::__source<_T1>())) == 1 + __is_convertible_imp::__is_convertible_test<_T1, _T2>::value +#if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !(!is_function<_T1>::value && !is_reference<_T1>::value && is_reference<_T2>::value && (!is_const::type>::value || is_volatile::type>::value) diff --git a/test/std/utilities/meta/meta.rel/is_convertible.pass.cpp b/test/std/utilities/meta/meta.rel/is_convertible.pass.cpp index 718e0ff18..429fb3303 100644 --- a/test/std/utilities/meta/meta.rel/is_convertible.pass.cpp +++ b/test/std/utilities/meta/meta.rel/is_convertible.pass.cpp @@ -186,4 +186,10 @@ int main() static_assert((std::is_convertible::value), ""); static_assert((std::is_convertible::value), ""); static_assert((!std::is_convertible::value), ""); +// This test requires Access control SFINAE which we only have in C++11 or when +// we are using the compiler builtin for is_convertible. +#if __cplusplus >= 201103L || !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK) + test_is_not_convertible(); +#endif + }