diff options
| author | Shuai Wang <shuaiwang@google.com> | 2018-09-11 20:05:37 +0000 |
|---|---|---|
| committer | Shuai Wang <shuaiwang@google.com> | 2018-09-11 20:05:37 +0000 |
| commit | 277b808ad394d0549972b08926b14f61c2017386 (patch) | |
| tree | 08facb4159150a3819a9f8a95225867864f3dc93 /clang-tools-extra/clang-tidy | |
| parent | 3dcdf9e416ecf1e83a0cec8e6a37920bc2d15085 (diff) | |
| download | bcm5719-llvm-277b808ad394d0549972b08926b14f61c2017386.tar.gz bcm5719-llvm-277b808ad394d0549972b08926b14f61c2017386.zip | |
[clang-tidy] Handle sugared reference types in ExprMutationAnalyzer
Summary:
This handles cases like this:
```
typedef int& IntRef;
void mutate(IntRef);
void f() {
int x;
mutate(x);
}
```
where the param type is a sugared type (`TypedefType`) instead of a
reference type directly.
Note that another category of similar but different cases are already
handled properly before:
```
typedef int Int;
void mutate(Int&);
void f() {
int x;
mutate(x);
}
```
Reviewers: aaron.ballman, alexfh, george.karpenkov
Subscribers: xazax.hun, a.sidorin, Szelethus, cfe-commits
Differential Revision: https://reviews.llvm.org/D50953
llvm-svn: 341986
Diffstat (limited to 'clang-tools-extra/clang-tidy')
| -rw-r--r-- | clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp b/clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp index 1ec1f7270f3..e04ac724c84 100644 --- a/clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp +++ b/clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp @@ -48,11 +48,13 @@ AST_MATCHER_P(GenericSelectionExpr, hasControllingExpr, } const auto nonConstReferenceType = [] { - return referenceType(pointee(unless(isConstQualified()))); + return hasUnqualifiedDesugaredType( + referenceType(pointee(unless(isConstQualified())))); }; const auto nonConstPointerType = [] { - return pointerType(pointee(unless(isConstQualified()))); + return hasUnqualifiedDesugaredType( + pointerType(pointee(unless(isConstQualified())))); }; const auto isMoveOnly = [] { @@ -185,12 +187,11 @@ const Stmt *ExprMutationAnalyzer::findDirectMutation(const Expr *Exp) { // Treat calling `operator->()` of move-only classes as taking address. // These are typically smart pointers with unique ownership so we treat // mutation of pointee as mutation of the smart pointer itself. - const auto AsOperatorArrowThis = cxxOperatorCallExpr( - hasOverloadedOperatorName("->"), - callee(cxxMethodDecl( - ofClass(isMoveOnly()), - returns(hasUnqualifiedDesugaredType(nonConstPointerType())))), - argumentCountIs(1), hasArgument(0, equalsNode(Exp))); + const auto AsOperatorArrowThis = + cxxOperatorCallExpr(hasOverloadedOperatorName("->"), + callee(cxxMethodDecl(ofClass(isMoveOnly()), + returns(nonConstPointerType()))), + argumentCountIs(1), hasArgument(0, equalsNode(Exp))); // Used as non-const-ref argument when calling a function. // An argument is assumed to be non-const-ref when the function is unresolved. |

