mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
AK: Rename the local variable in the TRY() macro to avoid name clashes
"result" is a tad bit too generic to provide a clash-free experience - we found instances in LibJS where this breaks already. Essentially this doesn't work: auto foo = TRY(bar(result)); Because it expands to the following within the TRY() scope: { auto result = bar(result); ... } And that of course fails: error: use of ‘result’ before deduction of ‘auto’ The simple solution here is to use a name that is much less likely to clash with anything used in the expression ("_temporary_result"). :^)
This commit is contained in:
parent
e5fde795e0
commit
cbdd069279
1 changed files with 6 additions and 6 deletions
12
AK/Try.h
12
AK/Try.h
|
@ -9,10 +9,10 @@
|
||||||
// NOTE: This macro works with any result type that has the expected APIs.
|
// NOTE: This macro works with any result type that has the expected APIs.
|
||||||
// It's designed with AK::Result and Kernel::KResult in mind.
|
// It's designed with AK::Result and Kernel::KResult in mind.
|
||||||
|
|
||||||
#define TRY(expression) \
|
#define TRY(expression) \
|
||||||
({ \
|
({ \
|
||||||
auto result = (expression); \
|
auto _temporary_result = (expression); \
|
||||||
if (result.is_error()) \
|
if (_temporary_result.is_error()) \
|
||||||
return result.release_error(); \
|
return _temporary_result.release_error(); \
|
||||||
result.release_value(); \
|
_temporary_result.release_value(); \
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue