fix_-wshadow_warning.patch 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Charles Kerr <[email protected]>
  3. Date: Fri, 7 Jul 2023 11:28:19 -0500
  4. Subject: fix: -Wshadow warning
  5. In utils.h's `ERROR_AND_ABORT` macro, rename the static local variable
  6. `args` to avoid -Wshadow warnings in code that calls `ERROR_AND_ABORT()`
  7. or `CHECK()` from a function that already has an `args` variable.
  8. This patch could be removed after upstreaming to Node.js.
  9. Example warning:
  10. In file included from ../../third_party/electron_node/src/inspector/runtime_agent.cc:3:
  11. In file included from ../../third_party/electron_node/src/env-inl.h:32:
  12. ../../third_party/electron_node/src/node_internals.h:72:3: error: declaration shadows a local variable [-Werror,-Wshadow]
  13. 72 | CHECK(args[0]->IsObject());
  14. | ^
  15. ../../third_party/electron_node/src/util.h:154:7: note: expanded from macro 'CHECK'
  16. 154 | ERROR_AND_ABORT(expr); \
  17. | ^
  18. ../../third_party/electron_node/src/util.h:132:38: note: expanded from macro 'ERROR_AND_ABORT'
  19. 132 | static const node::AssertionInfo args = { \
  20. | ^
  21. ../../third_party/electron_node/src/node_internals.h:67:67: note: previous declaration is here
  22. 67 | void GetSockOrPeerName(const v8::FunctionCallbackInfo<v8::Value>& args) {
  23. | ^
  24. 1 error generated.
  25. diff --git a/src/util.h b/src/util.h
  26. index 28873dbe4024df70a43fdc01ebd70c09acd118b0..f270efded6930f9fda56c7e277e0e3b4de6c91f4 100644
  27. --- a/src/util.h
  28. +++ b/src/util.h
  29. @@ -131,10 +131,10 @@ void DumpJavaScriptBacktrace(FILE* fp);
  30. do { \
  31. /* Make sure that this struct does not end up in inline code, but */ \
  32. /* rather in a read-only data section when modifying this code. */ \
  33. - static const node::AssertionInfo args = { \
  34. + static const node::AssertionInfo error_and_abort_args = { \
  35. __FILE__ ":" STRINGIFY(__LINE__), #expr, PRETTY_FUNCTION_NAME \
  36. }; \
  37. - node::Assert(args); \
  38. + node::Assert(error_and_abort_args); \
  39. } while (0)
  40. #ifdef __GNUC__