llvm-project
113256a8 - [clang-tidy] Fix `misc-const-correctness` false positive on writes through assigned pointers (#216050)

Commit
4 days ago
[clang-tidy] Fix `misc-const-correctness` false positive on writes through assigned pointers (#216050) `ExprPointeeResolve` did not resolve through `=`, so a write such as `*(p = q) = 0` was not recognized as mutating `p`'s pointee and the check suggested a `const` pointee that does not compile: ```cpp void func(int *ptr1) { int *ptr2 = ptr1; int *ptr3 = ptr1; *(ptr2 = ptr3) = 0; // warning: pointee of 'ptr2' can be declared 'const' } ``` Godbolt: https://godbolt.org/z/3o8qnEKs3 An assignment yields an lvalue for the LHS holding the value of the RHS, so the dereferenced object is reachable through both operands. Resolve through both, like the existing additive case. The RHS is already covered indirectly by AssignToNonConst, so the fix is the LHS. Fixes https://github.com/llvm/llvm-project/issues/216048.
Author
Parents
Loading