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
-Wpointer-bool-conversion/-Waddress misses an obvious case #82512
Comments
I think I filed/proposed this in an issue years ago #25841 ... |
FWIW this seems to be covered by clang-tidy https://clang.llvm.org/extra/clang-tidy/checks/readability/implicit-bool-conversion.html but unfortunately this rule also applies to other forms of conversions like |
So we end up here: llvm-project/clang/lib/Sema/SemaChecking.cpp Lines 15628 to 15632 in 004c197
and then we bail out here: llvm-project/clang/lib/Sema/SemaChecking.cpp Lines 16463 to 16465 in 004c197
I think what we need is a extra check in check for @AaronBallman seems like a good first issue. |
This does seem like a reasonable first issue and those steps are what I'd recommend as well. I don't think there are any surprises lurking in here that would trip someone up. |
Hi! This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below. |
@AaronBallman Hello! I would love to work on this issue. Could it be assigned to me? |
@vinayakdsci: Just create pull request and mention it on this page. |
@AaronBallman I was trying to follow the instructions provided by Shafik above, and I seem to be getting an assertion failure This is triggered when I try to emit a diagnostic with DiagID Do you have any ideas on how to fix this? I am unable to get it to work, and have tried a number of ways to avoid this assertion failure. This diagnostic I was able to locate in the diagnostic tablegen file Thanks! |
you might not be passing the right number of/enough parameters to the diagnostic? In the .td file you'll see the diagnostic text uses a number of placeholders (%0, etc I think) and you'll need to supply just as many to the diagnostic - mabye check another use of that diagnostic to see what/how the parameters are passed? |
@dwblaikie thanks for the advice, I was able to fix the errors. However, after the fixes, some of the existing tests are failing. How do you think I should proceed? Should I open a PR and wait for review, and then fix any errors? Thanks! |
I think the best way forward is to open a PR and then folks can see the code changes and verify they match the intent and we can see the CI failures for ourselves and that should help identify better unexpected outcomes. |
Adds diagnostics for lambda expressions being cast to boolean values, which results in the expression always evaluating to true. Earlier, Clang allowed compilation of such erroneous programs, but now emits a warning through `-Wpointer-bool-conversion`. Fixes #82512
The following pattern is often used to evaluate an expensive function only once, cache its result, and return that on subsequent calls.
But this code is subtly wrong. It should be
In the bad case it looks as though the lambda is being evaluated to a pointer(?) and this is being evaluated always to
true
when it is assigned tois_true
.It feels as though
-Wpointer-bool-conversion
should flag this, but it does not (godbolt).The text was updated successfully, but these errors were encountered: