summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-09-15 22:57:05 +0100
committerLinus Groh <mail@linusgroh.de>2021-09-15 23:46:53 +0100
commitcbdd06927927d2f4d4c27cd7bd283495cf7a2957 (patch)
tree385e2b4656438e05d808cca75ee0c8c737ed8a62 /AK
parente5fde795e0f0f082c06b6777491b2515aed02ace (diff)
downloadserenity-cbdd06927927d2f4d4c27cd7bd283495cf7a2957.zip
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"). :^)
Diffstat (limited to 'AK')
-rw-r--r--AK/Try.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/AK/Try.h b/AK/Try.h
index 862fc7dbc5..4efb21a5a0 100644
--- a/AK/Try.h
+++ b/AK/Try.h
@@ -9,10 +9,10 @@
// NOTE: This macro works with any result type that has the expected APIs.
// It's designed with AK::Result and Kernel::KResult in mind.
-#define TRY(expression) \
- ({ \
- auto result = (expression); \
- if (result.is_error()) \
- return result.release_error(); \
- result.release_value(); \
+#define TRY(expression) \
+ ({ \
+ auto _temporary_result = (expression); \
+ if (_temporary_result.is_error()) \
+ return _temporary_result.release_error(); \
+ _temporary_result.release_value(); \
})