summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-12-06 18:19:37 +0000
committerLinus Groh <mail@linusgroh.de>2022-12-06 21:31:00 +0000
commit5103e08b776d79fdfc78bbd7a8a9f65a63e7d841 (patch)
tree83519b1ba9f71a6f9ccde0ed8462edf4a56d0592
parentd2e143eec7a3fa54b28454da64861a7adb6bafc0 (diff)
downloadserenity-5103e08b776d79fdfc78bbd7a8a9f65a63e7d841.zip
AK: Ignore -Wshadow in TRY() and MUST()
This makes the warning in CLion disappear when nesting them.
-rw-r--r--AK/Try.h28
1 files changed, 17 insertions, 11 deletions
diff --git a/AK/Try.h b/AK/Try.h
index 58be3a64a3..772f0d6608 100644
--- a/AK/Try.h
+++ b/AK/Try.h
@@ -6,6 +6,8 @@
#pragma once
+#include <AK/Diagnostics.h>
+
// NOTE: This macro works with any result type that has the expected APIs.
// It's designed with AK::Result and AK::Error in mind.
//
@@ -14,17 +16,21 @@
// by at least clang and gcc.
// [1] https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
-#define TRY(expression) \
- ({ \
- auto _temporary_result = (expression); \
- if (_temporary_result.is_error()) [[unlikely]] \
- return _temporary_result.release_error(); \
- _temporary_result.release_value(); \
+#define TRY(expression) \
+ ({ \
+ /* Ignore -Wshadow to allow nesting the macro. */ \
+ AK_IGNORE_DIAGNOSTIC("-Wshadow", \
+ auto _temporary_result = (expression)); \
+ if (_temporary_result.is_error()) [[unlikely]] \
+ return _temporary_result.release_error(); \
+ _temporary_result.release_value(); \
})
-#define MUST(expression) \
- ({ \
- auto _temporary_result = (expression); \
- VERIFY(!_temporary_result.is_error()); \
- _temporary_result.release_value(); \
+#define MUST(expression) \
+ ({ \
+ /* Ignore -Wshadow to allow nesting the macro. */ \
+ AK_IGNORE_DIAGNOSTIC("-Wshadow", \
+ auto _temporary_result = (expression)); \
+ VERIFY(!_temporary_result.is_error()); \
+ _temporary_result.release_value(); \
})