mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:57:43 +00:00
AK: Check the return type in IsCallableWithArguments
Template argument are checked to ensure that the `Out` type is equal or convertible to the type returned by the invokee. Compilation now fails on: `Function<void()> f = []() -> int { return 0; };` But this is allowed: `Function<ErrorOr<int>()> f = []() -> int { return 0; };`
This commit is contained in:
parent
d9f632fee7
commit
79006c03b4
4 changed files with 21 additions and 15 deletions
|
@ -51,14 +51,14 @@ public:
|
|||
|
||||
template<typename CallableType>
|
||||
SafeFunction(CallableType&& callable)
|
||||
requires((AK::IsFunctionObject<CallableType> && IsCallableWithArguments<CallableType, In...> && !IsSame<RemoveCVReference<CallableType>, SafeFunction>))
|
||||
requires((AK::IsFunctionObject<CallableType> && IsCallableWithArguments<CallableType, Out, In...> && !IsSame<RemoveCVReference<CallableType>, SafeFunction>))
|
||||
{
|
||||
init_with_callable(forward<CallableType>(callable), CallableKind::FunctionObject);
|
||||
}
|
||||
|
||||
template<typename FunctionType>
|
||||
SafeFunction(FunctionType f)
|
||||
requires((AK::IsFunctionPointer<FunctionType> && IsCallableWithArguments<RemovePointer<FunctionType>, In...> && !IsSame<RemoveCVReference<FunctionType>, SafeFunction>))
|
||||
requires((AK::IsFunctionPointer<FunctionType> && IsCallableWithArguments<RemovePointer<FunctionType>, Out, In...> && !IsSame<RemoveCVReference<FunctionType>, SafeFunction>))
|
||||
{
|
||||
init_with_callable(move(f), CallableKind::FunctionPointer);
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ public:
|
|||
|
||||
template<typename CallableType>
|
||||
SafeFunction& operator=(CallableType&& callable)
|
||||
requires((AK::IsFunctionObject<CallableType> && IsCallableWithArguments<CallableType, In...>))
|
||||
requires((AK::IsFunctionObject<CallableType> && IsCallableWithArguments<CallableType, Out, In...>))
|
||||
{
|
||||
clear();
|
||||
init_with_callable(forward<CallableType>(callable));
|
||||
|
@ -94,7 +94,7 @@ public:
|
|||
|
||||
template<typename FunctionType>
|
||||
SafeFunction& operator=(FunctionType f)
|
||||
requires((AK::IsFunctionPointer<FunctionType> && IsCallableWithArguments<RemovePointer<FunctionType>, In...>))
|
||||
requires((AK::IsFunctionPointer<FunctionType> && IsCallableWithArguments<RemovePointer<FunctionType>, Out, In...>))
|
||||
{
|
||||
clear();
|
||||
if (f)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue