diff --git a/include/__functional_base b/include/__functional_base index 3274842dc..feb587f7b 100644 --- a/include/__functional_base +++ b/include/__functional_base @@ -306,97 +306,19 @@ struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile> #endif // _LIBCPP_HAS_NO_VARIADICS -// __invoke +#ifndef _LIBCPP_CXX03_LANG -#ifndef _LIBCPP_HAS_NO_VARIADICS - -// bullets 1 and 2 - -template -inline _LIBCPP_INLINE_VISIBILITY -auto -__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) - -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...)) -{ - return (_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...); -} - - -template -inline _LIBCPP_INLINE_VISIBILITY -auto -__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) - -> decltype((__a0.get().*__f)(_VSTD::forward<_Args>(__args)...)) -{ - return (__a0.get().*__f)(_VSTD::forward<_Args>(__args)...); -} - -template -inline _LIBCPP_INLINE_VISIBILITY -auto -__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) - -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...)) -{ - return ((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...); -} - -// bullets 3 and 4 - -template -inline _LIBCPP_INLINE_VISIBILITY -auto -__invoke(_Fp&& __f, _A0&& __a0) - -> decltype(_VSTD::forward<_A0>(__a0).*__f) -{ - return _VSTD::forward<_A0>(__a0).*__f; -} - - -template -inline _LIBCPP_INLINE_VISIBILITY -auto -__invoke(_Fp&& __f, _A0&& __a0) - -> decltype(__a0.get().*__f) -{ - return __a0.get().*__f; -} - -template -inline _LIBCPP_INLINE_VISIBILITY -auto -__invoke(_Fp&& __f, _A0&& __a0) - -> decltype((*_VSTD::forward<_A0>(__a0)).*__f) -{ - return (*_VSTD::forward<_A0>(__a0)).*__f; -} - -// bullet 5 - -template -inline _LIBCPP_INLINE_VISIBILITY -auto -__invoke(_Fp&& __f, _Args&& ...__args) - -> decltype(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...)) -{ - return _VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...); -} template struct __invoke_return { typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type; }; -#else // _LIBCPP_HAS_NO_VARIADICS +#else // defined(_LIBCPP_CXX03_LANG) #include <__functional_base_03> -#endif // _LIBCPP_HAS_NO_VARIADICS +#endif // !defined(_LIBCPP_CXX03_LANG) template diff --git a/include/experimental/tuple b/include/experimental/tuple index 50d1e0555..e00d2ec1a 100644 --- a/include/experimental/tuple +++ b/include/experimental/tuple @@ -57,9 +57,10 @@ _LIBCPP_CONSTEXPR size_t tuple_size_v = tuple_size<_Tp>::value; template inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR_AFTER_CXX11 decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t, integer_sequence) { - return _VSTD::__invoke( + return _VSTD::__invoke_constexpr( _VSTD::forward<_Fn>(__f), _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))... ); diff --git a/include/type_traits b/include/type_traits index d4b857e91..b4af37dd2 100644 --- a/include/type_traits +++ b/include/type_traits @@ -132,6 +132,14 @@ namespace std template struct is_base_of; template struct is_convertible; + template struct is_callable; // not defined + template + struct is_callable; + + template struct is_nothrow_callable; // not defined + template + struct is_nothrow_callable; + // Alignment properties and transformations: template struct alignment_of; template @@ -344,6 +352,10 @@ namespace std = is_base_of::value; // C++17 template constexpr bool is_convertible_v = is_convertible::value; // C++17 + template constexpr bool is_callable_v + = is_callable::value; // C++17 + template constexpr bool is_nothrow_callable_v + = is_nothrow_callable::value; // C++17 // [meta.logical], logical operator traits: template struct conjunction; // C++17 @@ -2739,6 +2751,15 @@ struct __member_pointer_traits // typedef ... _FnType; }; + +template +struct __member_pointer_class_type {}; + +template +struct __member_pointer_class_type<_Ret _ClassType::*> { + typedef _ClassType type; +}; + // result_of template class result_of; @@ -3971,7 +3992,7 @@ template struct __is_reference_wrapper_impl > template struct __is_reference_wrapper : public __is_reference_wrapper_impl::type> {}; -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_CXX03_LANG // Check for complete types @@ -4059,8 +4080,6 @@ struct __check_complete<_Rp (_Class::*)(_Param...) const volatile> { }; -#if __has_feature(cxx_reference_qualified_functions) - template struct __check_complete<_Rp (_Class::*)(_Param...) &> : private __check_complete<_Class> @@ -4109,8 +4128,6 @@ struct __check_complete<_Rp (_Class::*)(_Param...) const volatile&&> { }; -#endif - template struct __check_complete<_Rp _Class::*> : private __check_complete<_Class> @@ -4118,149 +4135,250 @@ struct __check_complete<_Rp _Class::*> }; -template -using __arg_is_base_of_ptm = - is_base_of::type>::_ClassType>::type, - typename remove_reference<_A0>::type>; +template ::type, + class _DecayA0 = typename decay<_A0>::type, + class _ClassT = typename __member_pointer_class_type<_DecayFp>::type> +using __enable_if_bullet1 = typename enable_if + < + is_member_function_pointer<_DecayFp>::value + && is_base_of<_ClassT, _DecayA0>::value + >::type; -template -using __arg_is_reference_wrapper = __is_reference_wrapper::type>; +template ::type, + class _DecayA0 = typename decay<_A0>::type> +using __enable_if_bullet2 = typename enable_if + < + is_member_function_pointer<_DecayFp>::value + && __is_reference_wrapper<_DecayA0>::value + >::type; + +template ::type, + class _DecayA0 = typename decay<_A0>::type, + class _ClassT = typename __member_pointer_class_type<_DecayFp>::type> +using __enable_if_bullet3 = typename enable_if + < + is_member_function_pointer<_DecayFp>::value + && !is_base_of<_ClassT, _DecayA0>::value + && !__is_reference_wrapper<_DecayA0>::value + >::type; + +template ::type, + class _DecayA0 = typename decay<_A0>::type, + class _ClassT = typename __member_pointer_class_type<_DecayFp>::type> +using __enable_if_bullet4 = typename enable_if + < + is_member_object_pointer<_DecayFp>::value + && is_base_of<_ClassT, _DecayA0>::value + >::type; + +template ::type, + class _DecayA0 = typename decay<_A0>::type> +using __enable_if_bullet5 = typename enable_if + < + is_member_object_pointer<_DecayFp>::value + && __is_reference_wrapper<_DecayA0>::value + >::type; + +template ::type, + class _DecayA0 = typename decay<_A0>::type, + class _ClassT = typename __member_pointer_class_type<_DecayFp>::type> +using __enable_if_bullet6 = typename enable_if + < + is_member_object_pointer<_DecayFp>::value + && !is_base_of<_ClassT, _DecayA0>::value + && !__is_reference_wrapper<_DecayA0>::value + >::type; // __invoke forward declarations // fall back - none of the bullets +#define _LIBCPP_INVOKE_RETURN(...) \ + noexcept(noexcept(__VA_ARGS__)) -> decltype(__VA_ARGS__) \ + { return __VA_ARGS__; } + template -auto -__invoke(__any, _Args&& ...__args) - -> __nat; +auto __invoke(__any, _Args&& ...__args) -> __nat; + +template +auto __invoke_constexpr(__any, _Args&& ...__args) -> __nat; // bullets 1, 2 and 3 template ::type>::value && - __arg_is_base_of_ptm<_Fp, _A0>::value - >::type - > -_LIBCPP_INLINE_VISIBILITY + class = __enable_if_bullet1<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY auto __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) - -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...)); - +_LIBCPP_INVOKE_RETURN((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...)) template ::type>::value && - __arg_is_reference_wrapper<_A0>::value - >::type - > -_LIBCPP_INLINE_VISIBILITY -auto -__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) - -> decltype((__a0.get().*__f)(_VSTD::forward<_Args>(__args)...)); + class = __enable_if_bullet1<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR auto +__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args) +_LIBCPP_INVOKE_RETURN((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...)) template ::type>::value && - !__arg_is_base_of_ptm<_Fp, _A0>::value && - !__arg_is_reference_wrapper<_A0>::value - >::type - > -_LIBCPP_INLINE_VISIBILITY + class = __enable_if_bullet2<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY auto __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) - -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...)); +_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(_VSTD::forward<_Args>(__args)...)) + +template > +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR auto +__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args) +_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(_VSTD::forward<_Args>(__args)...)) + +template > +inline _LIBCPP_INLINE_VISIBILITY +auto +__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) +_LIBCPP_INVOKE_RETURN(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...)) + +template > +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR auto +__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args) +_LIBCPP_INVOKE_RETURN(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...)) // bullets 4, 5 and 6 template ::type>::value && - __arg_is_base_of_ptm<_Fp, _A0>::value - >::type - > -_LIBCPP_INLINE_VISIBILITY + class = __enable_if_bullet4<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY auto __invoke(_Fp&& __f, _A0&& __a0) - -> decltype(_VSTD::forward<_A0>(__a0).*__f); - +_LIBCPP_INVOKE_RETURN(_VSTD::forward<_A0>(__a0).*__f) template ::type>::value && - __arg_is_reference_wrapper<_A0>::value - >::type - > -_LIBCPP_INLINE_VISIBILITY -auto -__invoke(_Fp&& __f, _A0&& __a0) - -> decltype(__a0.get().*__f); + class = __enable_if_bullet4<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR auto +__invoke_constexpr(_Fp&& __f, _A0&& __a0) +_LIBCPP_INVOKE_RETURN(_VSTD::forward<_A0>(__a0).*__f) template ::type>::value && - !__arg_is_base_of_ptm<_Fp, _A0>::value && - !__arg_is_reference_wrapper<_A0>::value - >::type - > -_LIBCPP_INLINE_VISIBILITY + class = __enable_if_bullet5<_Fp, _A0>> +inline _LIBCPP_INLINE_VISIBILITY auto __invoke(_Fp&& __f, _A0&& __a0) - -> decltype((*_VSTD::forward<_A0>(__a0)).*__f); +_LIBCPP_INVOKE_RETURN(__a0.get().*__f) + +template > +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR auto +__invoke_constexpr(_Fp&& __f, _A0&& __a0) +_LIBCPP_INVOKE_RETURN(__a0.get().*__f) + +template > +inline _LIBCPP_INLINE_VISIBILITY +auto +__invoke(_Fp&& __f, _A0&& __a0) +_LIBCPP_INVOKE_RETURN((*_VSTD::forward<_A0>(__a0)).*__f) + +template > +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR auto +__invoke_constexpr(_Fp&& __f, _A0&& __a0) +_LIBCPP_INVOKE_RETURN((*_VSTD::forward<_A0>(__a0)).*__f) // bullet 7 template -_LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY auto __invoke(_Fp&& __f, _Args&& ...__args) - -> decltype(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...)); +_LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...)) + +template +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR auto +__invoke_constexpr(_Fp&& __f, _Args&& ...__args) +_LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...)) + +#undef _LIBCPP_INVOKE_RETURN // __invokable -template -struct __invokable_imp +template +struct __invokable_r : private __check_complete<_Fp> { - typedef decltype( - __invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...) - ) type; - static const bool value = !is_same::value; + using _Result = decltype( + _VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...)); + + static const bool value = + conditional< + !is_same<_Result, __nat>::value, + typename conditional< + is_void<_Ret>::value, + true_type, + is_convertible<_Result, _Ret> + >::type, + false_type + >::type::value; }; template -struct __invokable - : public integral_constant::value> -{ +using __invokable = __invokable_r; + +template +struct __nothrow_invokable_r_imp { + static const bool value = false; }; -// __invoke_of - -template -struct __invoke_of_imp // false +template +struct __nothrow_invokable_r_imp { + typedef __nothrow_invokable_r_imp _ThisT; + + template + static void __test_noexcept(_Tp) noexcept; + + static const bool value = noexcept(_ThisT::__test_noexcept<_Ret>( + _VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...))); }; -template -struct __invoke_of_imp +template +struct __nothrow_invokable_r_imp { - typedef typename __invokable_imp<_Fp, _Args...>::type type; + static const bool value = noexcept( + _VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...)); }; +template +using __nothrow_invokable_r = + __nothrow_invokable_r_imp< + __invokable_r<_Ret, _Fp, _Args...>::value, + is_void<_Ret>::value, + _Ret, _Fp, _Args... + >; + template struct __invoke_of - : public __invoke_of_imp<__invokable<_Fp, _Args...>::value, _Fp, _Args...> + : public enable_if< + __invokable<_Fp, _Args...>::value, + typename __invokable_r::_Result> { }; +// result_of + template class _LIBCPP_TYPE_VIS_ONLY result_of<_Fp(_Args...)> : public __invoke_of<_Fp, _Args...> @@ -4271,7 +4389,36 @@ class _LIBCPP_TYPE_VIS_ONLY result_of<_Fp(_Args...)> template using result_of_t = typename result_of<_Tp>::type; #endif -#endif // _LIBCPP_HAS_NO_VARIADICS +#if _LIBCPP_STD_VER > 14 + +// is_callable + +template +struct _LIBCPP_TYPE_VIS_ONLY is_callable; + +template +struct _LIBCPP_TYPE_VIS_ONLY is_callable<_Fn(_Args...), _Ret> + : integral_constant::value> {}; + +template +constexpr bool is_callable_v = is_callable<_Fn, _Ret>::value; + +// is_nothrow_callable + +template +struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_callable; + +template +struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_callable<_Fn(_Args...), _Ret> + : integral_constant::value> +{}; + +template +constexpr bool is_nothrow_callable_v = is_nothrow_callable<_Fn, _Ret>::value; + +#endif // _LIBCPP_STD_VER > 14 + +#endif // !defined(_LIBCPP_CXX03_LANG) template inline _LIBCPP_INLINE_VISIBILITY diff --git a/test/std/experimental/utilities/tuple/tuple.apply/constexpr_types.pass.cpp b/test/std/experimental/utilities/tuple/tuple.apply/constexpr_types.pass.cpp index 2d700486f..5b8a8f09d 100644 --- a/test/std/experimental/utilities/tuple/tuple.apply/constexpr_types.pass.cpp +++ b/test/std/experimental/utilities/tuple/tuple.apply/constexpr_types.pass.cpp @@ -9,11 +9,6 @@ // UNSUPPORTED: c++98, c++03, c++11 -// TODO(ericwf) -// constexpr support temporarily reverted due to bug: -// https://llvm.org/bugs/show_bug.cgi?id=23141 -// XFAIL: * - // // template constexpr decltype(auto) apply(F &&, T &&) diff --git a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/PR23141_invoke_not_constexpr.pass.cpp b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/PR23141_invoke_not_constexpr.pass.cpp new file mode 100644 index 000000000..163b2d9af --- /dev/null +++ b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/PR23141_invoke_not_constexpr.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// template +// unspecified bind(Fn, Types...); +// template +// unspecified bind(Fn, Types...); + +// https://llvm.org/bugs/show_bug.cgi?id=23141 +#include +#include + +struct Fun +{ + template + void operator()(T && t, U && u) const + { + static_assert(std::is_same::value, ""); + } +}; + +int main() +{ + std::bind(Fun{}, std::placeholders::_1, 42)("hello"); +} diff --git a/test/std/utilities/function.objects/func.require/bullet_1_2_3.pass.cpp b/test/std/utilities/function.objects/func.require/bullet_1_2_3.pass.cpp index 09e8e2113..509c751b4 100644 --- a/test/std/utilities/function.objects/func.require/bullet_1_2_3.pass.cpp +++ b/test/std/utilities/function.objects/func.require/bullet_1_2_3.pass.cpp @@ -260,8 +260,11 @@ void test_derived_from_ref_wrap() { DerivedFromRefWrap d(x); auto get_fn = &std::reference_wrapper::get; auto& ret = std::__invoke(get_fn, r); + auto& cret = std::__invoke_constexpr(get_fn, r); assert(&ret == &x); + assert(&cret == &x); auto& ret2 = std::__invoke(get_fn, d); + auto& cret2 = std::__invoke_constexpr(get_fn, d); assert(&ret2 == &x); auto& ret3 = std::__invoke(get_fn, r2); assert(&ret3 == &x); diff --git a/test/std/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp b/test/std/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp index 2007c417a..803c501f8 100644 --- a/test/std/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp +++ b/test/std/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp @@ -185,11 +185,22 @@ private: #else void runTest(Fn M, T& obj, ObjectType* expect ) { #endif - static_assert((std::is_same< - decltype(std::__invoke(M, std::forward(obj))), Expect - >::value), ""); - Expect e = std::__invoke(M, std::forward(obj)); - assert(&e == expect); + { + static_assert((std::is_same< + decltype(std::__invoke(M, std::forward(obj))), Expect + >::value), ""); + Expect e = std::__invoke(M, std::forward(obj)); + assert(&e == expect); + } +#if TEST_STD_VER >= 11 + { + static_assert((std::is_same< + decltype(std::__invoke_constexpr(M, std::forward(obj))), Expect + >::value), ""); + Expect e = std::__invoke_constexpr(M, std::forward(obj)); + assert(&e == expect); + } +#endif } }; diff --git a/test/std/utilities/function.objects/func.require/invoke_helpers.h b/test/std/utilities/function.objects/func.require/invoke_helpers.h index 495703d0e..7e7a5fd24 100644 --- a/test/std/utilities/function.objects/func.require/invoke_helpers.h +++ b/test/std/utilities/function.objects/func.require/invoke_helpers.h @@ -271,89 +271,185 @@ private: ArgType a0, a1, a2; //========================================================================== - // BULLET 1 AND 2 TEST METHODS + // BULLET 1, 2 AND 3 TEST METHODS //========================================================================== template void runTestImp(Int<0>, MethodPtr ptr, ObjectT& object) { - static_assert((std::is_same< - decltype(std::__invoke(ptr, object_cast(object))) - , CallRet>::value), ""); - assert(ID::unchecked_call == false); - CallRet ret = std::__invoke(ptr, object_cast(object)); - assert(ID::checkCalled(ret)); + { + static_assert((std::is_same< + decltype(std::__invoke(ptr, object_cast(object))) + , CallRet>::value), ""); + assert(ID::unchecked_call == false); + CallRet ret = std::__invoke(ptr, object_cast(object)); + assert(ID::checkCalled(ret)); + } +#if TEST_STD_VER >= 11 + { + static_assert((std::is_same< + decltype(std::__invoke_constexpr(ptr, object_cast(object))) + , CallRet>::value), ""); + assert(ID::unchecked_call == false); + CallRet ret = std::__invoke_constexpr(ptr, object_cast(object)); + assert(ID::checkCalled(ret)); + } +#endif } template void runTestImp(Int<1>, MethodPtr ptr, ObjectT& object) { - static_assert((std::is_same< - decltype(std::__invoke(ptr, object_cast(object), arg_cast(a0))) - , CallRet>::value), ""); - assert(ID::unchecked_call == false); - CallRet ret = std::__invoke(ptr, object_cast(object), arg_cast(a0)); - assert(ID::checkCalled(ret)); + { + static_assert((std::is_same< + decltype(std::__invoke(ptr, object_cast(object), arg_cast(a0))) + , CallRet>::value), ""); + assert(ID::unchecked_call == false); + CallRet ret = std::__invoke(ptr, object_cast(object), arg_cast(a0)); + assert(ID::checkCalled(ret)); + } +#if TEST_STD_VER >= 11 + { + static_assert((std::is_same< + decltype(std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0))) + , CallRet>::value), ""); + assert(ID::unchecked_call == false); + CallRet ret = std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0)); + assert(ID::checkCalled(ret)); + } +#endif } template void runTestImp(Int<2>, MethodPtr ptr, ObjectT& object) { - static_assert((std::is_same< - decltype(std::__invoke(ptr, object_cast(object), arg_cast(a0), arg_cast(a1))) - , CallRet>::value), ""); - assert(ID::unchecked_call == false); - CallRet ret = std::__invoke(ptr, object_cast(object), arg_cast(a0), arg_cast(a1)); - assert(ID::checkCalled(ret)); + { + static_assert((std::is_same< + decltype(std::__invoke(ptr, object_cast(object), arg_cast(a0), arg_cast(a1))) + , CallRet>::value), ""); + assert(ID::unchecked_call == false); + CallRet ret = std::__invoke(ptr, object_cast(object), arg_cast(a0), arg_cast(a1)); + assert(ID::checkCalled(ret)); + } +#if TEST_STD_VER >= 11 + { + static_assert((std::is_same< + decltype(std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0), arg_cast(a1))) + , CallRet>::value), ""); + assert(ID::unchecked_call == false); + CallRet ret = std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0), arg_cast(a1)); + assert(ID::checkCalled(ret)); + } +#endif } template void runTestImp(Int<3>, MethodPtr ptr, ObjectT& object) { - static_assert((std::is_same< - decltype(std::__invoke(ptr, object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2))) - , CallRet>::value), ""); - assert(ID::unchecked_call == false); - CallRet ret = std::__invoke(ptr, object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2)); - assert(ID::checkCalled(ret)); + { + static_assert((std::is_same< + decltype(std::__invoke(ptr, object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2))) + , CallRet>::value), ""); + assert(ID::unchecked_call == false); + CallRet ret = std::__invoke(ptr, object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2)); + assert(ID::checkCalled(ret)); + } +#if TEST_STD_VER >= 11 + { + static_assert((std::is_same< + decltype(std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2))) + , CallRet>::value), ""); + assert(ID::unchecked_call == false); + CallRet ret = std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2)); + assert(ID::checkCalled(ret)); + } +#endif } //========================================================================== - // BULLET 5 TEST METHODS + // BULLET 7 TEST METHODS //========================================================================== template void runTestImp(Int<0>, ObjectT& object) { - static_assert((std::is_same< - decltype(std::__invoke(object_cast(object))) - , CallRet>::value), ""); - assert(ID::unchecked_call == false); - CallRet ret = std::__invoke(object_cast(object)); - assert(ID::checkCalled(ret)); + { + static_assert((std::is_same< + decltype(std::__invoke(object_cast(object))) + , CallRet>::value), ""); + assert(ID::unchecked_call == false); + CallRet ret = std::__invoke(object_cast(object)); + assert(ID::checkCalled(ret)); + } +#if TEST_STD_VER >= 11 + { + static_assert((std::is_same< + decltype(std::__invoke_constexpr(object_cast(object))) + , CallRet>::value), ""); + assert(ID::unchecked_call == false); + CallRet ret = std::__invoke_constexpr(object_cast(object)); + assert(ID::checkCalled(ret)); + } +#endif } template void runTestImp(Int<1>, ObjectT& object) { - static_assert((std::is_same< - decltype(std::__invoke(object_cast(object), arg_cast(a0))) - , CallRet>::value), ""); - assert(ID::unchecked_call == false); - CallRet ret = std::__invoke(object_cast(object), arg_cast(a0)); - assert(ID::checkCalled(ret)); + { + static_assert((std::is_same< + decltype(std::__invoke(object_cast(object), arg_cast(a0))) + , CallRet>::value), ""); + assert(ID::unchecked_call == false); + CallRet ret = std::__invoke(object_cast(object), arg_cast(a0)); + assert(ID::checkCalled(ret)); + } +#if TEST_STD_VER >= 11 + { + static_assert((std::is_same< + decltype(std::__invoke_constexpr(object_cast(object), arg_cast(a0))) + , CallRet>::value), ""); + assert(ID::unchecked_call == false); + CallRet ret = std::__invoke_constexpr(object_cast(object), arg_cast(a0)); + assert(ID::checkCalled(ret)); + } +#endif } template void runTestImp(Int<2>, ObjectT& object) { - static_assert((std::is_same< - decltype(std::__invoke(object_cast(object), arg_cast(a0), arg_cast(a1))) - , CallRet>::value), ""); - assert(ID::unchecked_call == false); - CallRet ret = std::__invoke(object_cast(object), arg_cast(a0), arg_cast(a1)); - assert(ID::checkCalled(ret)); + { + static_assert((std::is_same< + decltype(std::__invoke(object_cast(object), arg_cast(a0), arg_cast(a1))) + , CallRet>::value), ""); + assert(ID::unchecked_call == false); + CallRet ret = std::__invoke(object_cast(object), arg_cast(a0), arg_cast(a1)); + assert(ID::checkCalled(ret)); + } +#if TEST_STD_VER >= 11 + { + static_assert((std::is_same< + decltype(std::__invoke_constexpr(object_cast(object), arg_cast(a0), arg_cast(a1))) + , CallRet>::value), ""); + assert(ID::unchecked_call == false); + CallRet ret = std::__invoke_constexpr(object_cast(object), arg_cast(a0), arg_cast(a1)); + assert(ID::checkCalled(ret)); + } +#endif } template void runTestImp(Int<3>, ObjectT& object) { - static_assert((std::is_same< - decltype(std::__invoke(object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2))) - , CallRet>::value), ""); - assert(ID::unchecked_call == false); - CallRet ret = std::__invoke(object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2)); - assert(ID::checkCalled(ret)); + { + static_assert((std::is_same< + decltype(std::__invoke(object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2))) + , CallRet>::value), ""); + assert(ID::unchecked_call == false); + CallRet ret = std::__invoke(object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2)); + assert(ID::checkCalled(ret)); + } +#if TEST_STD_VER >= 11 + { + static_assert((std::is_same< + decltype(std::__invoke_constexpr(object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2))) + , CallRet>::value), ""); + assert(ID::unchecked_call == false); + CallRet ret = std::__invoke_constexpr(object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2)); + assert(ID::checkCalled(ret)); + } +#endif } }; diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp index aa77dab51..3e4a99e98 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03 + // // shared_ptr @@ -55,7 +57,6 @@ int main() } assert(A::count == 0); assert(test_allocator::alloc_count == 0); -#if __cplusplus >= 201103L { int i = 67; char c = 'e'; @@ -74,5 +75,4 @@ int main() assert(p->get_char() == 'f'); } assert(A::count == 0); -#endif } diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_no_variadics.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_cxx03.pass.cpp similarity index 98% rename from test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_no_variadics.pass.cpp rename to test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_cxx03.pass.cpp index 8dcd50e49..f6350c72b 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_no_variadics.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_cxx03.pass.cpp @@ -14,7 +14,7 @@ // template // shared_ptr allocate_shared(const A& a, Args&&... args); -#define _LIBCPP_HAS_NO_VARIADICS + #include #include #include diff --git a/test/std/utilities/meta/meta.rel/is_callable.pass.cpp b/test/std/utilities/meta/meta.rel/is_callable.pass.cpp new file mode 100644 index 000000000..7de65835f --- /dev/null +++ b/test/std/utilities/meta/meta.rel/is_callable.pass.cpp @@ -0,0 +1,159 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11, c++14 + +// type_traits + +// is_callable + +// Most testing of is_callable is done within the [meta.trans.other] result_of +// tests. + +#include +#include + +#include "test_macros.h" + +struct Tag {}; +struct DerFromTag : Tag {}; + +struct Implicit { + Implicit(int) {} +}; + +struct Explicit { + explicit Explicit(int) {} +}; + +struct NotCallableWithInt { + int operator()(int) = delete; + int operator()(Tag) { return 42; } +}; + +int main() +{ + { + using Fn = int(Tag::*)(int); + using RFn = int(Tag::*)(int) &&; + // INVOKE bullet 1, 2 and 3 + { + // Bullet 1 + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(!std::is_callable::value); + static_assert(!std::is_callable::value); + static_assert(!std::is_callable::value); + } + { + // Bullet 2 + using T = std::reference_wrapper; + using DT = std::reference_wrapper; + using CT = std::reference_wrapper; + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(!std::is_callable::value); + static_assert(!std::is_callable::value); + } + { + // Bullet 3 + using T = Tag*; + using DT = DerFromTag*; + using CT = const Tag*; + using ST = std::unique_ptr; + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(!std::is_callable::value); + static_assert(!std::is_callable::value); + } + } + { + // Bullets 4, 5 and 6 + using Fn = int (Tag::*); + static_assert(!std::is_callable::value); + { + // Bullet 4 + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + } + { + // Bullet 5 + using T = std::reference_wrapper; + using DT = std::reference_wrapper; + using CT = std::reference_wrapper; + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + } + { + // Bullet 6 + using T = Tag*; + using DT = DerFromTag*; + using CT = const Tag*; + using ST = std::unique_ptr; + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + } + } + { + // INVOKE bullet 7 + { + // Function pointer + using Fp = void(*)(Tag&, int); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(!std::is_callable::value); + static_assert(!std::is_callable::value); + static_assert(!std::is_callable::value); + } + { + // Function reference + using Fp = void(&)(Tag&, int); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(!std::is_callable::value); + static_assert(!std::is_callable::value); + static_assert(!std::is_callable::value); + } + { + // Function object + using Fn = NotCallableWithInt; + static_assert(std::is_callable::value, ""); + static_assert(!std::is_callable::value, ""); + } + } + { + // Check that the conversion to the return type is properly checked + using Fn = int(*)(); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(std::is_callable::value); + static_assert(!std::is_callable::value); + } + { + // Check for is_callable_v + using Fn = void(*)(); + static_assert(std::is_callable_v); + static_assert(!std::is_callable_v); + } +} diff --git a/test/std/utilities/meta/meta.rel/is_nothrow_callable.pass.cpp b/test/std/utilities/meta/meta.rel/is_nothrow_callable.pass.cpp new file mode 100644 index 000000000..c36a460af --- /dev/null +++ b/test/std/utilities/meta/meta.rel/is_nothrow_callable.pass.cpp @@ -0,0 +1,115 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11, c++14 + +// type_traits + +// is_nothrow_callable + +#include +#include + +#include "test_macros.h" + +struct Tag {}; + +struct Implicit { + Implicit(int) noexcept {} +}; + +struct ThrowsImplicit { + ThrowsImplicit(int) {} +}; + +struct Explicit { + explicit Explicit(int) noexcept {} +}; + +template +struct CallObject { + Ret operator()(Args&&...) const noexcept(IsNoexcept); +}; + +template +constexpr bool throws_callable() { + return std::is_callable::value && + !std::is_nothrow_callable::value; +} + +template +constexpr bool throws_callable() { + return std::is_callable::value && + !std::is_nothrow_callable::value; +} + +// FIXME(EricWF) Don't test the where noexcept is *not* part of the type system +// once implementations have caught up. +void test_noexcept_function_pointers() +{ + struct Dummy { void foo() noexcept; static void bar() noexcept; }; +#if !defined(__cpp_noexcept_function_type) + { + // Check that PMF's and function pointers *work*. is_nothrow_callable will always + // return false because 'noexcept' is not part of the function type. + static_assert(throws_callable()); + static_assert(throws_callable()); + } +#else + { + // Check that PMF's and function pointers actually work and that + // is_nothrow_callable returns true for noexcept PMF's and function + // pointers. + static_assert(std::is_nothrow_callable::value); + static_assert(std::is_nothrow_callable::value); + } +#endif +} + +int main() +{ + { + // Check that the conversion to the return type is properly checked + using Fn = CallObject; + static_assert(std::is_nothrow_callable::value); + static_assert(std::is_nothrow_callable::value); + static_assert(std::is_nothrow_callable::value); + static_assert(throws_callable()); + static_assert(!std::is_nothrow_callable()); + } + { + // Check that the conversion to the parameters is properly checked + using Fn = CallObject; + static_assert(std::is_nothrow_callable::value); + static_assert(std::is_nothrow_callable::value); + static_assert(throws_callable()); + static_assert(!std::is_nothrow_callable::value); + } + { + // Check that the noexcept-ness of function objects is checked. + using Fn = CallObject; + using Fn2 = CallObject; + static_assert(std::is_nothrow_callable::value); + static_assert(throws_callable()); + } + { + // Check that PMD derefs are noexcept + using Fn = int (Tag::*); + static_assert(std::is_nothrow_callable::value); + static_assert(std::is_nothrow_callable::value); + static_assert(throws_callable()); + } + { + // Check for is_nothrow_callable_v + using Fn = CallObject; + static_assert(std::is_nothrow_callable_v); + static_assert(!std::is_nothrow_callable_v); + } + test_noexcept_function_pointers(); +} diff --git a/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp index 3ac7d1bc9..fc01b22c3 100644 --- a/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp +++ b/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp @@ -45,6 +45,10 @@ struct HasType::type> : std::true_type {}; template void test_result_of() { +#if TEST_STD_VER > 14 + static_assert(std::is_callable::value, ""); + static_assert(std::is_callable::value, ""); +#endif static_assert((std::is_same::type, U>::value), ""); } @@ -54,6 +58,9 @@ void test_no_result() #if TEST_STD_VER >= 11 static_assert((!HasType >::value), ""); #endif +#if TEST_STD_VER > 14 + static_assert(std::is_callable::value == false, ""); +#endif } int main() diff --git a/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp index a00887384..8cb5853bb 100644 --- a/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp +++ b/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp @@ -35,6 +35,10 @@ void test_result_of_imp() #if TEST_STD_VER > 11 static_assert((std::is_same, U>::value), ""); #endif +#if TEST_STD_VER > 14 + static_assert(std::is_callable::value, ""); + static_assert(std::is_callable::value, ""); +#endif } int main() diff --git a/www/cxx1z_status.html b/www/cxx1z_status.html index 1c8e0db54..41a697846 100644 --- a/www/cxx1z_status.html +++ b/www/cxx1z_status.html @@ -92,7 +92,7 @@ P0030R1LWGProposal to Introduce a 3-Argument Overload to std::hypotJacksonville P0031R0LWGA Proposal to Add Constexpr Modifiers to reverse_iterator, move_iterator, array and Range AccessJacksonville P0272R1LWGGive std::string a non-const .data() member functionJacksonvilleComplete3.9 - P0077R2LWGis_callable, the missing INVOKE related traitJacksonville + P0077R2LWGis_callable, the missing INVOKE related traitJacksonvilleComplete3.9