mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:57:44 +00:00
AK+Kernel: Fix perfect forwarding constructors shadowing others
If a non-const lvalue reference is passed to these constructors, the converting constructor will be selected instead of the desired copy/move constructor. Since I needed to touch `KResultOr` anyway, I made the forwarding converting constructor use `forward<U>` instead of `move`. This meant that previously, if a lvalue was passed to it, a move operation took place even if no `move()` was called on it. Member initializers and if-else statements have been changed to match our current coding style.
This commit is contained in:
parent
a2e0291172
commit
62f84e94c8
2 changed files with 16 additions and 10 deletions
|
@ -62,13 +62,13 @@ public:
|
|||
}
|
||||
|
||||
template<typename CallableType>
|
||||
Function(CallableType&& callable) requires((IsFunctionObject<CallableType> && IsCallableWithArguments<CallableType, In...>))
|
||||
Function(CallableType&& callable) requires((IsFunctionObject<CallableType> && IsCallableWithArguments<CallableType, In...> && !IsSame<RemoveCVReference<CallableType>, Function>))
|
||||
{
|
||||
init_with_callable(forward<CallableType>(callable));
|
||||
}
|
||||
|
||||
template<typename FunctionType>
|
||||
Function(FunctionType f) requires((IsFunctionPointer<FunctionType> && IsCallableWithArguments<RemovePointer<FunctionType>, In...>))
|
||||
Function(FunctionType f) requires((IsFunctionPointer<FunctionType> && IsCallableWithArguments<RemovePointer<FunctionType>, In...> && !IsSame<RemoveCVReference<FunctionType>, Function>))
|
||||
{
|
||||
init_with_callable(move(f));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue