Skip to content
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

Interpreter warns when calling [[nodiscard]] functions #11562

Closed
hahnjo opened this issue Oct 14, 2022 · 2 comments · Fixed by #12654
Closed

Interpreter warns when calling [[nodiscard]] functions #11562

hahnjo opened this issue Oct 14, 2022 · 2 comments · Fixed by #12654

Comments

@hahnjo
Copy link
Member

hahnjo commented Oct 14, 2022

Similar to #8622, but in the interpreter:

root [0] std::vector<int> v;
root [1] v.size()
ROOT_prompt_1:1:1: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
v.size()
^~~~~~
(unsigned long) 0

(with libstdc++12)

This currently makes roottest-cling-stl-default-VectorSort fail with GCC 12.

@jalopezg-git
Copy link
Collaborator

jalopezg-git commented Oct 14, 2022

Thanks for the report, @hahnjo!

IIRC, this one was not trivial to fix, as in principle, we only want to ignore diag::warn_unused_result if (i) value capture is enabled, and (ii) only for the last parsed statement.
However, as the diagnostic is emitted during parsing (see SemaStmt.cpp), I think the only way of conditionally emitting this warning -given the two conditions above-, would be to buffer all the diagnostics and then filter this one based on the cling::CompilationOptions and the source location.

Otherwise, we can always fallback to the naive fix of just disable/filter this diagnostic in every case.

@hahnjo
Copy link
Member Author

hahnjo commented Oct 14, 2022

Yes, I agree this is non-trivial to fix after reading through #8622. But I decided to open an issue just to keep track of the problem because it affects a test with GCC 12; not sure if we can do anything for that one in particular in the test code...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants