summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
diff options
context:
space:
mode:
authorSamuel Benzaquen <sbenza@google.com>2018-01-15 18:03:20 +0000
committerSamuel Benzaquen <sbenza@google.com>2018-01-15 18:03:20 +0000
commitc814872cb887a31e5de6422439ffd3c640c7951a (patch)
treec7ef3f9568ad34a8f06f606aa1f580081fccec2c /clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
parentf630047ef6b7fb496961c10d3f4bdbc43a75251b (diff)
downloadbcm5719-llvm-c814872cb887a31e5de6422439ffd3c640c7951a.tar.gz
bcm5719-llvm-c814872cb887a31e5de6422439ffd3c640c7951a.zip
[clang-tidy] Expand readability-redundant-smartptr-get to understand implicit converions to bool in more contexts.
Summary: Expand readability-redundant-smartptr-get to understand implicit converions to bool in more contexts. Reviewers: hokein Subscribers: klimek, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D41998 llvm-svn: 322497
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
index dd6866f5a32..1abd70bd048 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
@@ -51,6 +51,20 @@ void registerMatchersForGetArrowStart(MatchFinder *Finder,
unaryOperator(hasOperatorName("*"),
hasUnaryOperand(callToGet(QuacksLikeASmartptr))),
Callback);
+
+ // Catch '!ptr.get()'
+ const auto CallToGetAsBool = ignoringParenImpCasts(callToGet(recordDecl(
+ QuacksLikeASmartptr, has(cxxConversionDecl(returns(booleanType()))))));
+ Finder->addMatcher(
+ unaryOperator(hasOperatorName("!"), hasUnaryOperand(CallToGetAsBool)),
+ Callback);
+
+ // Catch 'if(ptr.get())'
+ Finder->addMatcher(ifStmt(hasCondition(CallToGetAsBool)), Callback);
+
+ // Catch 'ptr.get() ? X : Y'
+ Finder->addMatcher(conditionalOperator(hasCondition(CallToGetAsBool)),
+ Callback);
}
void registerMatchersForGetEquals(MatchFinder *Finder,
@@ -72,11 +86,6 @@ void registerMatchersForGetEquals(MatchFinder *Finder,
hasEitherOperand(callToGet(IsAKnownSmartptr))),
Callback);
- // Matches against if(ptr.get())
- Finder->addMatcher(
- ifStmt(hasCondition(ignoringImpCasts(callToGet(IsAKnownSmartptr)))),
- Callback);
-
// FIXME: Match and fix if (l.get() == r.get()).
}
OpenPOWER on IntegriCloud