From 33dbb6c40ccf44e4b4c879270b6286e2829d057b Mon Sep 17 00:00:00 2001 From: Chiara Mooney <34109996+chiaramooney@users.noreply.github.com> Date: Mon, 8 Aug 2022 03:50:58 -0700 Subject: [PATCH] Fix Make Unused Not Compiler Specific (#34357) Summary: Use of `__attribute__` and `__unused` is compiler specific. Opt for standard `[[maybe_unused]]` instead. ## Changelog [General] [Fixed] - Remove compiler-specific syntax. Pull Request resolved: https://github.com/facebook/react-native/pull/34357 Test Plan: Built on react-native-windows. Reviewed By: cipolleschi Differential Revision: D38498481 Pulled By: javache fbshipit-source-id: af43206788f54dda3b747b6417e20096c7d520e8 --- React/Base/RCTModuleMethod.mm | 2 +- ReactCommon/cxxreact/JSExecutor.h | 3 +-- ReactCommon/cxxreact/NativeToJsBridge.cpp | 4 ++-- ReactCommon/cxxreact/SampleCxxModule.cpp | 2 +- ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/React/Base/RCTModuleMethod.mm b/React/Base/RCTModuleMethod.mm index 941400a9f2dee9..f2d32d9aaf708f 100644 --- a/React/Base/RCTModuleMethod.mm +++ b/React/Base/RCTModuleMethod.mm @@ -91,7 +91,7 @@ static BOOL RCTParseSelectorPart(const char **input, NSMutableString *selector) static BOOL RCTParseUnused(const char **input) { return RCTReadString(input, "__attribute__((unused))") || RCTReadString(input, "__attribute__((__unused__))") || - RCTReadString(input, "__unused"); + RCTReadString(input, "__unused") || RCTReadString(input, "[[maybe_unused]]"); } static RCTNullability RCTParseNullability(const char **input) diff --git a/ReactCommon/cxxreact/JSExecutor.h b/ReactCommon/cxxreact/JSExecutor.h index 18125ed04274d6..4d6e45f9c3792d 100644 --- a/ReactCommon/cxxreact/JSExecutor.h +++ b/ReactCommon/cxxreact/JSExecutor.h @@ -128,8 +128,7 @@ class RN_EXPORT JSExecutor { */ virtual std::string getDescription() = 0; - virtual void handleMemoryPressure(__attribute__((unused)) int pressureLevel) { - } + virtual void handleMemoryPressure([[maybe_unused]] int pressureLevel) {} virtual void destroy() {} virtual ~JSExecutor() {} diff --git a/ReactCommon/cxxreact/NativeToJsBridge.cpp b/ReactCommon/cxxreact/NativeToJsBridge.cpp index 88a933915e8473..ce54a90dea0afd 100644 --- a/ReactCommon/cxxreact/NativeToJsBridge.cpp +++ b/ReactCommon/cxxreact/NativeToJsBridge.cpp @@ -52,7 +52,7 @@ class JsToNativeBridge : public react::ExecutorDelegate { } void callNativeModules( - __attribute__((unused)) JSExecutor &executor, + [[maybe_unused]] JSExecutor &executor, folly::dynamic &&calls, bool isEndOfBatch) override { CHECK(m_registry || calls.empty()) @@ -85,7 +85,7 @@ class JsToNativeBridge : public react::ExecutorDelegate { } MethodCallResult callSerializableNativeHook( - __attribute__((unused)) JSExecutor &executor, + [[maybe_unused]] JSExecutor &executor, unsigned int moduleId, unsigned int methodId, folly::dynamic &&args) override { diff --git a/ReactCommon/cxxreact/SampleCxxModule.cpp b/ReactCommon/cxxreact/SampleCxxModule.cpp index c84aa1594ec4d6..2474be8ad689fc 100644 --- a/ReactCommon/cxxreact/SampleCxxModule.cpp +++ b/ReactCommon/cxxreact/SampleCxxModule.cpp @@ -163,7 +163,7 @@ void SampleCxxModule::save(folly::dynamic args) { sample_->save(std::move(m)); } -void SampleCxxModule::load(__unused folly::dynamic args, Callback cb) { +void SampleCxxModule::load([[maybe_unused]] folly::dynamic args, Callback cb) { dynamic d = dynamic::object; for (const auto &p : sample_->load()) { d.insert(p.first, p.second); diff --git a/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp b/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp index d9fa242de9c724..10552e0adae077 100644 --- a/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp +++ b/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp @@ -173,7 +173,7 @@ void JSIExecutor::setBundleRegistry(std::unique_ptr r) { PropNameID::forAscii(*runtime_, "nativeRequire"), 2, [this]( - __unused Runtime &rt, + [[maybe_unused]] Runtime &rt, const facebook::jsi::Value &, const facebook::jsi::Value *args, size_t count) { return nativeRequire(args, count); }));