-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: ignore unused warning for inspector-agent.cc #13188
src: ignore unused warning for inspector-agent.cc #13188
Conversation
Currently the following compiler warning is displayed: ../src/inspector_agent.cc:218:5: warning: ignoring return value of function declared with warn_unused_result attribute [-Wunused-result] callback->Call(env_->context(), receiver, 1, &argument); ^~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. This commit does a static cast of the result as there are tests that fail if we try to do something like ToLocalChecked.
@@ -215,7 +215,7 @@ class JsBindingsSessionDelegate : public InspectorSessionDelegate { | |||
Local<Value> argument = v8string.ToLocalChecked().As<Value>(); | |||
Local<Function> callback = callback_.Get(isolate); | |||
Local<Object> receiver = receiver_.Get(isolate); | |||
callback->Call(env_->context(), receiver, 1, &argument); | |||
static_cast<void>(callback->Call(env_->context(), receiver, 1, &argument)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't
#pragma GCC unused-result push
#pragma GCC unused-result ignored
callback->Call(env_->context(), receiver, 1, &argument)
#pragma GCC unused-result pop
be better, so it could be traced in the future
Or even just a comment stating the the // static_cast<void> is to skip 'unused-result' warning
?
Dismissed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No comment on the portability of the pragma, but there is no reason to cast to void other than to avoid warnings and visually document that the return value is explicitly being ignored, I don't think a comment is needed for that usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed if we document this somewhere as an idiom static_cast<void> === #pragma GCC unused-result ignored
Because a quick search only found one other use, in this file in line 210@master 352@here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we don't have a style guide, I'll add a note to #12791
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Casting to void is standard C++, https://stackoverflow.com/questions/689677/why-cast-unused-return-values-to-void, unlike GCC pramas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already agreed 👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I thought you wanted this documented as a node-specific style. Nice emoji use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but coverity can also be suppressed using a comment (search src/
for coverity).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sorry if this is documented somewhere but I must have missed it, is there a way to run coverity or get to the actual reports an other way then at this page? I would have thought that any warning from coverity would go away with the casting suggested in this pull request. |
I think @cjihrig was implying that adding the comment would be an alternative approach to casting to void (but I agree that casting is better than just to explicitly disable the warning for a single tool), not that this PR doesn’t suffice. |
Landed in 2db6556 |
Currently the following compiler warning is displayed: ../src/inspector_agent.cc:218:5: warning: ignoring return value of function declared with warn_unused_result attribute [-Wunused-result] callback->Call(env_->context(), receiver, 1, &argument); ^~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. This commit does a static cast of the result as there are tests that fail if we try to do something like ToLocalChecked. PR-URL: #13188 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Ah I got it now. Thanks! |
Currently the following compiler warning is displayed: ../src/inspector_agent.cc:218:5: warning: ignoring return value of function declared with warn_unused_result attribute [-Wunused-result] callback->Call(env_->context(), receiver, 1, &argument); ^~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. This commit does a static cast of the result as there are tests that fail if we try to do something like ToLocalChecked. PR-URL: #13188 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This does not land cleanly in LTS. Please feel free to manually backport. Please also feel free to replace do-not-land if it is being backported |
Currently the following compiler warning is displayed:
This commit does a static cast of the result as there are tests that
fail if we try to do something like ToLocalChecked.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
src