Bug 1665026 - Prevent ToResultInvoke from being instantiated with a raw pointer result type. r=janv

Differential Revision: https://phabricator.services.mozilla.com/D90264
This commit is contained in:
Simon Giesecke 2020-09-16 15:11:56 +00:00
Родитель 084f4ffe27
Коммит ab0b7510ad
1 изменённых файлов: 8 добавлений и 0 удалений

Просмотреть файл

@ -66,6 +66,14 @@ template <typename R, typename RArgMapper, typename Func, typename... Args>
Result<R, nsresult> ToResultInvokeInternal(const Func& aFunc,
const RArgMapper& aRArgMapper,
Args&&... aArgs) {
// XXX Thereotically, if R is a pointer to a non-refcounted type, this might
// be a non-owning pointer, but unless we find a case where this actually is
// relevant, it's safe to forbid any raw pointer result.
static_assert(
!std::is_pointer_v<R>,
"Raw pointer results are not supported, please specify a smart pointer "
"result type explicitly, so that getter_AddRefs is used");
R res;
nsresult rv = aFunc(std::forward<Args>(aArgs)..., aRArgMapper(res));
if (NS_FAILED(rv)) {