-
Notifications
You must be signed in to change notification settings - Fork 13.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
[clang-tidy] Check request: readability-use-map-at #133319
Comments
@llvm/issue-subscribers-clang-tidy Author: Denis Mikhailov (denzor200) Needs a check that will find an usage of
|
Using Clean and safe modern code would look like this: if (const auto I = values.find(""); I != values.end()) {
process(I->second);
} |
a micro performance downgrade is acceptable for a check in "readability" section I suppose.
This is a serious behaviour change. Some users may never expect silence, they would prefer explicit error shown from exception. |
Erm, I would say "no" to that. It is just about "readability" which should not introduce any functional changes. I have not encountered it so far but from what I understand introducing exception handling could have quite an performance impact.
So is introducing the throwing of an exception. So either solution isn't right - possibly the wrong group to put it into. The issue you are trying to fix here is about an unchecked access. That is similar to dereferencing an invalid pointer or an out-of-bounds access thus a potential bug. |
I think we all agree on the "unsafety" of the code, but there's disagreement on what the solution should be, which is not surprising. Everyone has their own error handling strategy: exceptions, assertions, logging, etc, etc. So I think the check should just warn and not provide any concrete solution/fix-it, leaving it up to the user to follow the error handling guidelines applicable to their project. Then this check could be moved to |
Needs a check that will find an usage of
std::map::find
without result's checking and will suggest to usestd::map::at
instead.The text was updated successfully, but these errors were encountered: