[clang-tidy] Add ExprMutationAnalyzer, that analyzes whether an expression is mutated...
authorAlexander Kornienko <alexfh@google.com>
Wed, 27 Jun 2018 14:30:55 +0000 (14:30 +0000)
committerAlexander Kornienko <alexfh@google.com>
Wed, 27 Jun 2018 14:30:55 +0000 (14:30 +0000)
commit271e181c7801c2885d768bc7c3692184eac549a7
tree089ee859439796935addfde5b223cc1845835ae4
parentcadcfed7aac7be93ec0fded17ac81d3517c7ddf3
[clang-tidy] Add ExprMutationAnalyzer, that analyzes whether an expression is mutated within a statement.

Summary:
(Originally started as a clang-tidy check but there's already D45444 so shifted to just adding ExprMutationAnalyzer)

`ExprMutationAnalyzer` is a generally useful helper that can be used in different clang-tidy checks for checking whether a given expression is (potentially) mutated within a statement (typically the enclosing compound statement.)

This is a more general and more powerful/accurate version of isOnlyUsedAsConst, which is used in ForRangeCopyCheck, UnnecessaryCopyInitialization.

It should also be possible to construct checks like D45444 (suggest adding const to variable declaration) or https://bugs.llvm.org/show_bug.cgi?id=21981 (suggest adding const to member function) using this helper function.

This function is tested by itself and is intended to stay generally useful instead of tied to any particular check.

Reviewers: hokein, alexfh, aaron.ballman, ilya-biryukov, george.karpenkov

Reviewed By: aaron.ballman

Subscribers: lebedev.ri, shuaiwang, rnkovacs, hokein, alexfh, aaron.ballman, a.sidorin, Eugene.Zelenko, xazax.hun, JonasToth, klimek, mgorny, cfe-commits

Tags: #clang-tools-extra

Patch by Shuai Wang.

Differential Revision: https://reviews.llvm.org/D45679

llvm-svn: 335736
clang-tools-extra/clang-tidy/utils/CMakeLists.txt
clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp [new file with mode: 0644]
clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.h [new file with mode: 0644]
clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
clang-tools-extra/unittests/clang-tidy/ExprMutationAnalyzerTest.cpp [new file with mode: 0644]