-
Notifications
You must be signed in to change notification settings - Fork 15.7k
[clang-tidy] doesNotMutateObject: Handle calls to member functions …
#94362
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
Changes from 1 commit
8a7e3ee
6c521ec
40b3287
b3d455f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -36,6 +36,111 @@ void extractNodesByIdTo(ArrayRef<BoundNodes> Matches, StringRef ID, | |||||
| Nodes.insert(Match.getNodeAs<Node>(ID)); | ||||||
| } | ||||||
|
|
||||||
| // If `D` has a const-qualified overload with otherwise identical | ||||||
| // ref-qualifiers, returns that overload. | ||||||
| const CXXMethodDecl *findConstOverload(const CXXMethodDecl &D) { | ||||||
| assert(!D.isConst()); | ||||||
|
|
||||||
| DeclContext::lookup_result lookup_result = | ||||||
| D.getParent()->lookup(D.getNameInfo().getName()); | ||||||
| if (lookup_result.isSingleResult()) { | ||||||
| // No overload. | ||||||
| return nullptr; | ||||||
| } | ||||||
| for (const Decl *overload : lookup_result) { | ||||||
| const CXXMethodDecl *candidate = dyn_cast<CXXMethodDecl>(overload); | ||||||
|
||||||
| const CXXMethodDecl *candidate = dyn_cast<CXXMethodDecl>(overload); | |
| const auto *candidate = dyn_cast<CXXMethodDecl>(overload); |
Type is explicitly stated in same statement.
Outdated
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.
It looks like we look up by name, do we also need to confirm that the return types are the same, or would overloading otherwise not be allowed and that's why it's implied?
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.
Overloading would be allowed in this case, but I think having a const overload with the same parameter types is enough to say that the use is immutable (not that the case when the return value is non-const and the object might be modified through the return value is caught by (C)). I've added a test to make this explicit (weird_overload()).
That being said, your comment made me realize that we were not checking that the parameter types were the same. Done and added tests (at(Tag1)). Thanks :)
Uh oh!
There was an error while loading. Please reload this page.