[clang-tidy] performance-unnecessary-copy-initialization: Prevent false positives...
authorFelix Berger <flx@google.com>
Fri, 20 Nov 2020 21:31:52 +0000 (16:31 -0500)
committerFelix Berger <flx@google.com>
Thu, 10 Dec 2020 21:58:17 +0000 (16:58 -0500)
commit671ad580610ad91139358b7786e02ff70433a90e
tree2b5f156680772db8bb3f34481a592b7dfcf77fb6
parent0978c83e6fcc7a8aea18e24eb3b2ad5523581757
[clang-tidy] performance-unnecessary-copy-initialization: Prevent false positives when dependent variable is modified.

Extend the check to not only look at the variable the unnecessarily copied
variable is initialized from, but also ensure that any variable the old variable
references is not modified.

Extend DeclRefExprUtils to also count references and pointers to const assigned
from the DeclRef we check for const usages.

Reviewed-by: aaron.ballman
Differential Revision: https://reviews.llvm.org/D91893
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
clang-tools-extra/clang-tidy/utils/Matchers.h
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp