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
[cling] Ignore -Wunused-result in wrapped code #12654
[cling] Ignore -Wunused-result in wrapped code #12654
Conversation
Make `FilteringDiagConsumer` also ignore -Wunused-result. Whether or not such diagnostic is filtered depends on `CompilationOptions::IgnorePromptDiags`. In particular, `IgnorePromptDiags` should _only_ be enabled for code parsed via `Interpreter::EvaluateInternal()`. Thus, as of this commit `IgnorePromptDiags` defaults to 0 in `makeDefaultCompilationOpts()` The observable effect of this change is ignoring `-Wunused-result` for wrapped code, e.g. ```c++ [[nodiscard]] int f() { return 0; } // This yields `warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]` void g() { f(); } f(); // but this should not ```
Starting build on |
Build failed on ROOT-debian10-i386/soversion. Failing tests: |
Build failed on ROOT-ubuntu2004/python3. Failing tests: |
Build failed on ROOT-ubuntu18.04/nortcxxmod. Failing tests: |
Build failed on ROOT-performance-centos8-multicore/cxx17. Failing tests: |
Build failed on mac12/noimt. Failing tests: |
Both tests fail due to the change in the default value for Taking a look at the test, to return something from the entry point of a macro seems legal even if the function is This seems a legitimate error that was being filtered (see here); I think the test should be fixed. |
Build failed on windows10/cxx14. Failing tests: |
Build failed on mac11/cxx14. Failing tests: |
If I understand correctly, with this patch neither:
will issue the warning ... which seems wrong. The issue being addressed is:
where we are in a use case where the warning is literally speaking incorrect since we do use the value and actually print it. i.e. Semantically, it seems that:
should/could issue the warning while
should definitively not issue the warning. So a genuine question is "is the fix here 'too broad' ? " and/or "is the "better" fix so expensive that it is better overall to suppress the warning globally?" |
I agree that both tests should be fixed to not have functions that returns a value when declared to return void.
should continue to work (i.e. return in unnamed macros) |
Actually, the first line does issue a warning (which is expected), while it is suppressed in the second case.
I have pasted below the current state of affairs after applying the patch in this PR (i.e., root [0] std::vector<int> v;
root [1] v.size()
(unsigned long) 0
root [2] // `return` was intentionally ommitted in f() below
root [3] size_t f() { v.size(); }
ROOT_prompt_3:1:14: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
size_t f() { v.size(); }
^~~~~~
ROOT_prompt_3:1:24: warning: non-void function does not return a value [-Wreturn-type]
size_t f() { v.size(); }
^
It's a bit too broad, as it suppresses the warning in wrapped code even if the expression is not part of value capture/printing. Given that the diagnostic is emitted in |
ok fair enough. This looks good then. Did you also test going through the |
And I confirm that it does, as code in unnamed macros is wrapped as needed. |
I think |
@wlav, fyi. |
Does having nodiscard avoid stack corruption if we still forget to return a result? |
No, I don't think it has any effect on that. |
Unless @Axel-Naumann, @vgvassilev or @hahnjo suggest otherwise, the only thing missing is to fix the two failing tests reported above. EDIT: sibling roottest PR is root-project/roottest#951. |
As of PR root-project/root#12654, returning a non-`void` expression from `void`-returning function is only valid in an unnamed macro (in which case the diagnostic is filtered).
@phsft-bot build |
Starting build on |
As of PR root-project/root#12654, returning a non-`void` expression from `void`-returning function is only valid in an unnamed macro (in which case the diagnostic is filtered).
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.
LG
As of PR root-project/root#12654, returning a non-`void` expression from `void`-returning function is only valid in an unnamed macro (in which case the diagnostic is filtered). Cherry-picked from a905ea5.
As of PR root-project/root#12654, returning a non-`void` expression from `void`-returning function is only valid in an unnamed macro (in which case the diagnostic is filtered). Cherry-picked from a905ea5.
This diagnostic should always be promoted to error, regardless of the ignoring state in `FilteringDiagConsumer`. This fixes the SourceCall/ErrorMacro.C test. The failure became visible after merging root-project#12654, given that `IgnorePromptDiags` now defaults to 0 in `makeDefaultCompilationOptions()`.
This diagnostic should always be promoted to error, regardless of the ignoring state in `FilteringDiagConsumer`. This fixes the SourceCall/ErrorMacro.C test. The failure became visible after merging root-project#12654, given that `IgnorePromptDiags` now defaults to 0 in `makeDefaultCompilationOptions()`.
This diagnostic should always be promoted to error, regardless of the ignoring state in `FilteringDiagConsumer`. This fixes the SourceCall/ErrorMacro.C test. The failure became visible after merging root-project#12654, given that `IgnorePromptDiags` now defaults to 0 in `makeDefaultCompilationOptions()`.
This diagnostic should always be promoted to error, regardless of the ignoring state in `FilteringDiagConsumer`. This fixes the SourceCall/ErrorMacro.C test. The failure became visible after merging root-project#12654, given that `IgnorePromptDiags` now defaults to 0 in `makeDefaultCompilationOptions()`.
This diagnostic should always be promoted to error, regardless of the ignoring state in `FilteringDiagConsumer`. This fixes the SourceCall/ErrorMacro.C test. The failure became visible after merging #12654, given that `IgnorePromptDiags` now defaults to 0 in `makeDefaultCompilationOptions()`.
This diagnostic should always be promoted to error, regardless of the ignoring state in `FilteringDiagConsumer`. This fixes the SourceCall/ErrorMacro.C test. The failure became visible after merging #12654, given that `IgnorePromptDiags` now defaults to 0 in `makeDefaultCompilationOptions()`.
This diagnostic should always be promoted to error, regardless of the ignoring state in `FilteringDiagConsumer`. This fixes the SourceCall/ErrorMacro.C test. The failure became visible after merging root-project/root#12654, given that `IgnorePromptDiags` now defaults to 0 in `makeDefaultCompilationOptions()`.
This diagnostic should always be promoted to error, regardless of the ignoring state in `FilteringDiagConsumer`. This fixes the SourceCall/ErrorMacro.C test. The failure became visible after merging root-project#12654, given that `IgnorePromptDiags` now defaults to 0 in `makeDefaultCompilationOptions()`.
This diagnostic should always be promoted to error, regardless of the ignoring state in `FilteringDiagConsumer`. This fixes the SourceCall/ErrorMacro.C test. The failure became visible after merging root-project#12654, given that `IgnorePromptDiags` now defaults to 0 in `makeDefaultCompilationOptions()`.
Make
FilteringDiagConsumer
also ignore -Wunused-result. Whether or not such diagnostic is filtered depends onCompilationOptions::IgnorePromptDiags
.In particular,
IgnorePromptDiags
should only be enabled for code parsed viaInterpreter::EvaluateInternal()
. Thus, as of this commitIgnorePromptDiags
defaults to 0 inmakeDefaultCompilationOpts()
The observable effect of this change is ignoring
-Wunused-result
for wrapped code, e.g.Alternatively, as discussed with @Axel-Naumann, we could insert
#pragma clang diagnositc ...
directives inInterpreter::WrapInput()
, but I see that as much less elegant.Checklist:
This PR fixes #11562.