mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:47:34 +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:
parent
3de75f6436
commit
afc0e461e1
11 changed files with 86 additions and 54 deletions
|
@ -77,15 +77,17 @@ private:
|
|||
DeprecatedString m_description;
|
||||
};
|
||||
|
||||
#define DECODER_TRY(category, expression) \
|
||||
({ \
|
||||
auto _result = ((expression)); \
|
||||
if (_result.is_error()) [[unlikely]] { \
|
||||
auto _error_string = _result.release_error().string_literal(); \
|
||||
return DecoderError::from_source_location( \
|
||||
((category)), _error_string, SourceLocation::current()); \
|
||||
} \
|
||||
_result.release_value(); \
|
||||
#define DECODER_TRY(category, expression) \
|
||||
({ \
|
||||
auto _result = ((expression)); \
|
||||
if (_result.is_error()) [[unlikely]] { \
|
||||
auto _error_string = _result.release_error().string_literal(); \
|
||||
return DecoderError::from_source_location( \
|
||||
((category)), _error_string, SourceLocation::current()); \
|
||||
} \
|
||||
static_assert(!IsLvalueReference<decltype(_result.release_value())>, \
|
||||
"Do not return a reference from a fallible expression"); \
|
||||
_result.release_value(); \
|
||||
})
|
||||
|
||||
#define DECODER_TRY_ALLOC(expression) DECODER_TRY(DecoderErrorCategory::Memory, expression)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue