Fixes PR#51776. If the object on which size() is called has an overloaded operator->, the span for E will include the ->, and since the return type of operator-> is a pointer, readability-container-size-empty will try to add another arrow, leading to the nonsensical vp->->empty() suggestion. This patch fixes this behavior.
Details
Details
Diff Detail
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Comment Actions
Could you please add a test case where the smart pointer object is dereferenced before calling size()? E.g. return (*ptr).size() == 0;. I think this change doesn't work on this test case.
Comment Actions
This is not entirely true; what you're seeing is an existing, unrelated bug: https://godbolt.org/z/9zEfdrPW8
In any case, I've fixed it, added a test for it, and added a bullet point to the release notes.
Comment Actions
Thanks for improving this check! I think it looks great and safe enough. It would be better to turn !(*ptr).empty() into !ptr->empty(), but I have no particular opinions at this point. Let's see if @aaron.ballman has any comments.