Open
Bug 1670897
Opened 5 years ago
Updated 3 years ago
After moving to C++20, support propagating errors from cleanup functions with QM_TRY
Categories
(Core :: Storage: Quota Manager, task)
Core
Storage: Quota Manager
Tracking
()
NEW
People
(Reporter: sg, Unassigned)
References
Details
To allow using a failable cleanup handler with QM_TRY, e.g.:
nsDependentSubstring subdirNameBase;
IDB_TRY(
OkIf(GetFilenameBase(subdirName, kFileManagerDirectoryNameSuffix,
subdirNameBase)),
Ok{},
([&directory, &subdirName](const NotOk) -> Result<Ok, nsresult> {
// If there is an unexpected directory in the idb directory,
// trying to delete at first instead of breaking the whole
// initialization.
IDB_TRY(DeleteFilesNoQuota(directory, subdirName),
Err(NS_ERROR_UNEXPECTED));
return Ok{};
}));
the definition of QM_TRY_CUSTOM_RET_VAL_WITH_CLEANUP could be changed to:
#define QM_TRY_CUSTOM_RET_VAL_WITH_CLEANUP(ns, tryResult, expr, customRetVal, \
cleanup) \
auto tryResult = ::mozilla::ToResult(expr); \
static_assert(std::is_empty_v<typename decltype(tryResult)::ok_type>); \
if (MOZ_UNLIKELY(tryResult.isErr())) { \
auto tryTempError = tryResult.unwrapErr(); \
ns::QM_HANDLE_ERROR(expr); \
if constexpr (std::is_same_v<void, decltype(cleanup(tryTempError))>) { \
cleanup(tryTempError); \
} else { \
QM_TRY_PROPAGATE_ERR(ns, MOZ_UNIQUE_VAR(tryResult), \
cleanup(tryTempError)); \
} \
return customRetVal; \
}
This requires the C++20 feature of allowing the use of lambda expressions in unevaluated contexts.
Maybe there is a C++17 solution for this, but I didn't find one yet.
| Reporter | ||
Comment 1•5 years ago
|
||
Actually, this is not possible: if constexpr can only be used in a template, so this part would somehow need to move inside a template.
| Reporter | ||
Updated•5 years ago
|
Summary: After moving to C++20, supporting propagating errors from cleanup functions with QM_TRY → After moving to C++20, support propagating errors from cleanup functions with QM_TRY
You need to log in
before you can comment on or make changes to this bug.
Description
•