1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:07:35 +00:00

AK+Everywhere: Disallow returning a reference from a fallible expression

This will silently make a copy. Rather than masking this behavior, let's
explicitly disallow it.
This commit is contained in:
Timothy Flynn 2023-01-13 15:48:09 -05:00 committed by Tim Flynn
parent 3de75f6436
commit afc0e461e1
11 changed files with 86 additions and 54 deletions

View file

@ -231,12 +231,14 @@ struct CLDR {
// Some parsing is expected to fail. For example, the CLDR contains language mappings
// with locales such as "en-GB-oed" that are canonically invalid locale IDs.
#define TRY_OR_DISCARD(expression) \
({ \
auto _temporary_result = (expression); \
if (_temporary_result.is_error()) \
return; \
_temporary_result.release_value(); \
#define TRY_OR_DISCARD(expression) \
({ \
auto _temporary_result = (expression); \
if (_temporary_result.is_error()) \
return; \
static_assert(!IsLvalueReference<decltype(_temporary_result.release_value())>, \
"Do not return a reference from a fallible expression"); \
_temporary_result.release_value(); \
})
static ErrorOr<LanguageMapping> parse_language_mapping(CLDR& cldr, StringView key, StringView alias)