From f5d253dcfa696156081b1ba75410d9572506e0cb Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sat, 14 Jan 2023 16:34:44 -0700 Subject: [PATCH] Everywhere: Fully qualify IsLvalueReference in TRY() macros If USING_AK_GLOBALLY is not defined, the name IsLvalueReference might not be available in the global namespace. Follow the pattern established in LibTest to fully qualify AK types in macros to avoid this problem. --- AK/Try.h | 39 ++++++++++--------- Kernel/Net/Socket.h | 16 ++++---- .../LibLocale/GenerateLocaleData.cpp | 16 ++++---- Userland/Libraries/LibAudio/LoaderError.h | 16 ++++---- Userland/Libraries/LibJS/Runtime/Completion.h | 24 ++++++------ .../LibJS/Runtime/PromiseCapability.h | 4 +- Userland/Libraries/LibVideo/DecoderError.h | 22 +++++------ .../Libraries/LibVideo/PlaybackManager.cpp | 2 +- .../LibWeb/Fetch/Fetching/Fetching.cpp | 16 ++++---- .../LibWeb/WebDriver/ExecuteScript.cpp | 16 ++++---- Userland/Utilities/matroska.cpp | 20 +++++----- 11 files changed, 96 insertions(+), 95 deletions(-) diff --git a/AK/Try.h b/AK/Try.h index 81b0fca9f32..b3dff1b2730 100644 --- a/AK/Try.h +++ b/AK/Try.h @@ -7,6 +7,7 @@ #pragma once #include +#include // NOTE: This macro works with any result type that has the expected APIs. // It's designed with AK::Result and AK::Error in mind. @@ -20,25 +21,25 @@ // from a fallible expression. This will not do what you want; the statement expression // will create a copy regardless, so it is explicitly disallowed. -#define TRY(expression) \ - ({ \ - /* Ignore -Wshadow to allow nesting the macro. */ \ - AK_IGNORE_DIAGNOSTIC("-Wshadow", \ - auto _temporary_result = (expression)); \ - static_assert(!IsLvalueReference, \ - "Do not return a reference from a fallible 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)); \ + static_assert(!::AK::Detail::IsLvalueReference, \ + "Do not return a reference from a fallible expression"); \ + if (_temporary_result.is_error()) [[unlikely]] \ + return _temporary_result.release_error(); \ + _temporary_result.release_value(); \ }) -#define MUST(expression) \ - ({ \ - /* Ignore -Wshadow to allow nesting the macro. */ \ - AK_IGNORE_DIAGNOSTIC("-Wshadow", \ - auto _temporary_result = (expression)); \ - static_assert(!IsLvalueReference, \ - "Do not return a reference from a fallible 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)); \ + static_assert(!::AK::Detail::IsLvalueReference, \ + "Do not return a reference from a fallible expression"); \ + VERIFY(!_temporary_result.is_error()); \ + _temporary_result.release_value(); \ }) diff --git a/Kernel/Net/Socket.h b/Kernel/Net/Socket.h index b5bc494a77f..09047399744 100644 --- a/Kernel/Net/Socket.h +++ b/Kernel/Net/Socket.h @@ -184,14 +184,14 @@ private: }; // This is a special variant of TRY() that also updates the socket's SO_ERROR field on error. -#define SOCKET_TRY(expression) \ - ({ \ - auto result = (expression); \ - if (result.is_error()) \ - return set_so_error(result.release_error()); \ - static_assert(!IsLvalueReference, \ - "Do not return a reference from a fallible expression"); \ - result.release_value(); \ +#define SOCKET_TRY(expression) \ + ({ \ + auto result = (expression); \ + if (result.is_error()) \ + return set_so_error(result.release_error()); \ + static_assert(!::AK::Detail::IsLvalueReference, \ + "Do not return a reference from a fallible expression"); \ + result.release_value(); \ }) } diff --git a/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateLocaleData.cpp b/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateLocaleData.cpp index 11059aa9aef..ab1136e458e 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateLocaleData.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateLocaleData.cpp @@ -231,14 +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; \ - static_assert(!IsLvalueReference, \ - "Do not return a reference from a fallible expression"); \ - _temporary_result.release_value(); \ +#define TRY_OR_DISCARD(expression) \ + ({ \ + auto _temporary_result = (expression); \ + if (_temporary_result.is_error()) \ + return; \ + static_assert(!::AK::Detail::IsLvalueReference, \ + "Do not return a reference from a fallible expression"); \ + _temporary_result.release_value(); \ }) static ErrorOr parse_language_mapping(CLDR& cldr, StringView key, StringView alias) diff --git a/Userland/Libraries/LibAudio/LoaderError.h b/Userland/Libraries/LibAudio/LoaderError.h index e659050f38b..a54a0489022 100644 --- a/Userland/Libraries/LibAudio/LoaderError.h +++ b/Userland/Libraries/LibAudio/LoaderError.h @@ -66,12 +66,12 @@ struct LoaderError { } // Convenience TRY-like macro to convert an Error to a LoaderError -#define LOADER_TRY(expression) \ - ({ \ - auto _temporary_result = (expression); \ - if (_temporary_result.is_error()) \ - return LoaderError(_temporary_result.release_error()); \ - static_assert(!IsLvalueReference, \ - "Do not return a reference from a fallible expression"); \ - _temporary_result.release_value(); \ +#define LOADER_TRY(expression) \ + ({ \ + auto _temporary_result = (expression); \ + if (_temporary_result.is_error()) \ + return LoaderError(_temporary_result.release_error()); \ + static_assert(!::AK::Detail::IsLvalueReference, \ + "Do not return a reference from a fallible expression"); \ + _temporary_result.release_value(); \ }) diff --git a/Userland/Libraries/LibJS/Runtime/Completion.h b/Userland/Libraries/LibJS/Runtime/Completion.h index fed974f7b61..8fa7566b61b 100644 --- a/Userland/Libraries/LibJS/Runtime/Completion.h +++ b/Userland/Libraries/LibJS/Runtime/Completion.h @@ -16,18 +16,18 @@ namespace JS { -#define TRY_OR_THROW_OOM(vm, expression) \ - ({ \ - /* Ignore -Wshadow to allow nesting the macro. */ \ - AK_IGNORE_DIAGNOSTIC("-Wshadow", \ - auto _temporary_result = (expression)); \ - if (_temporary_result.is_error()) { \ - VERIFY(_temporary_result.error().code() == ENOMEM); \ - return vm.throw_completion(JS::ErrorType::OutOfMemory); \ - } \ - static_assert(!IsLvalueReference, \ - "Do not return a reference from a fallible expression"); \ - _temporary_result.release_value(); \ +#define TRY_OR_THROW_OOM(vm, expression) \ + ({ \ + /* Ignore -Wshadow to allow nesting the macro. */ \ + AK_IGNORE_DIAGNOSTIC("-Wshadow", \ + auto _temporary_result = (expression)); \ + if (_temporary_result.is_error()) { \ + VERIFY(_temporary_result.error().code() == ENOMEM); \ + return vm.throw_completion(JS::ErrorType::OutOfMemory); \ + } \ + static_assert(!::AK::Detail::IsLvalueReference, \ + "Do not return a reference from a fallible expression"); \ + _temporary_result.release_value(); \ }) // 6.2.3 The Completion Record Specification Type, https://tc39.es/ecma262/#sec-completion-record-specification-type diff --git a/Userland/Libraries/LibJS/Runtime/PromiseCapability.h b/Userland/Libraries/LibJS/Runtime/PromiseCapability.h index fac53cadb3f..41c4b81170b 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseCapability.h +++ b/Userland/Libraries/LibJS/Runtime/PromiseCapability.h @@ -53,7 +53,7 @@ private: return (capability)->promise(); \ } \ \ - static_assert(!IsLvalueReference, \ + static_assert(!::AK::Detail::IsLvalueReference, \ "Do not return a reference from a fallible expression"); \ \ /* 2. Else if value is a Completion Record, set value to value.[[Value]]. */ \ @@ -79,7 +79,7 @@ private: return Value { (capability)->promise() }; \ } \ \ - static_assert(!IsLvalueReference, \ + static_assert(!::AK::Detail::IsLvalueReference, \ "Do not return a reference from a fallible expression"); \ \ /* 2. Else if value is a Completion Record, set value to value.[[Value]]. */ \ diff --git a/Userland/Libraries/LibVideo/DecoderError.h b/Userland/Libraries/LibVideo/DecoderError.h index 94a7b739934..b377b2552a2 100644 --- a/Userland/Libraries/LibVideo/DecoderError.h +++ b/Userland/Libraries/LibVideo/DecoderError.h @@ -77,17 +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()); \ - } \ - static_assert(!IsLvalueReference, \ - "Do not return a reference from a fallible expression"); \ - _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(!::AK::Detail::IsLvalueReference, \ + "Do not return a reference from a fallible expression"); \ + _result.release_value(); \ }) #define DECODER_TRY_ALLOC(expression) DECODER_TRY(DecoderErrorCategory::Memory, expression) diff --git a/Userland/Libraries/LibVideo/PlaybackManager.cpp b/Userland/Libraries/LibVideo/PlaybackManager.cpp index acb14feefb4..672bf4dbedb 100644 --- a/Userland/Libraries/LibVideo/PlaybackManager.cpp +++ b/Userland/Libraries/LibVideo/PlaybackManager.cpp @@ -273,7 +273,7 @@ bool PlaybackManager::decode_and_queue_one_sample() m_present_timer->start(0); \ return false; \ } \ - static_assert(!IsLvalueReference, \ + static_assert(!::AK::Detail::IsLvalueReference, \ "Do not return a reference from a fallible expression"); \ _temporary_result.release_value(); \ }) diff --git a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index b3a8c92401a..d22f67a004d 100644 --- a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -42,14 +42,14 @@ namespace Web::Fetch::Fetching { -#define TRY_OR_IGNORE(expression) \ - ({ \ - auto _temporary_result = (expression); \ - if (_temporary_result.is_error()) \ - return; \ - static_assert(!IsLvalueReference, \ - "Do not return a reference from a fallible expression"); \ - _temporary_result.release_value(); \ +#define TRY_OR_IGNORE(expression) \ + ({ \ + auto _temporary_result = (expression); \ + if (_temporary_result.is_error()) \ + return; \ + static_assert(!::AK::Detail::IsLvalueReference, \ + "Do not return a reference from a fallible expression"); \ + _temporary_result.release_value(); \ }) // https://fetch.spec.whatwg.org/#concept-fetch diff --git a/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp b/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp index 2c414b47aa2..c9da79077fc 100644 --- a/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp @@ -31,14 +31,14 @@ namespace Web::WebDriver { -#define TRY_OR_JS_ERROR(expression) \ - ({ \ - auto _temporary_result = (expression); \ - if (_temporary_result.is_error()) [[unlikely]] \ - return ExecuteScriptResultType::JavaScriptError; \ - static_assert(!IsLvalueReference, \ - "Do not return a reference from a fallible expression"); \ - _temporary_result.release_value(); \ +#define TRY_OR_JS_ERROR(expression) \ + ({ \ + auto _temporary_result = (expression); \ + if (_temporary_result.is_error()) [[unlikely]] \ + return ExecuteScriptResultType::JavaScriptError; \ + static_assert(!::AK::Detail::IsLvalueReference, \ + "Do not return a reference from a fallible expression"); \ + _temporary_result.release_value(); \ }) static ErrorOr internal_json_clone_algorithm(JS::Realm&, JS::Value, HashTable& seen); diff --git a/Userland/Utilities/matroska.cpp b/Userland/Utilities/matroska.cpp index ac551a4d864..bd36e3809ef 100644 --- a/Userland/Utilities/matroska.cpp +++ b/Userland/Utilities/matroska.cpp @@ -10,16 +10,16 @@ #include #include -#define TRY_PARSE(expression) \ - ({ \ - auto _temporary_result = ((expression)); \ - if (_temporary_result.is_error()) [[unlikely]] { \ - outln("Encountered a parsing error: {}", _temporary_result.error().string_literal()); \ - return Error::from_string_literal("Failed to parse :("); \ - } \ - static_assert(!IsLvalueReference, \ - "Do not return a reference from a fallible expression"); \ - _temporary_result.release_value(); \ +#define TRY_PARSE(expression) \ + ({ \ + auto _temporary_result = ((expression)); \ + if (_temporary_result.is_error()) [[unlikely]] { \ + outln("Encountered a parsing error: {}", _temporary_result.error().string_literal()); \ + return Error::from_string_literal("Failed to parse :("); \ + } \ + static_assert(!::AK::Detail::IsLvalueReference, \ + "Do not return a reference from a fallible expression"); \ + _temporary_result.release_value(); \ }) ErrorOr serenity_main(Main::Arguments arguments)