forked from OSchip/llvm-project
Revert r282382; it had no reference to Revision.
llvm-svn: 282384
This commit is contained in:
parent
dc288a896e
commit
9d68b64c00
|
@ -60,26 +60,20 @@ void registerMatchersForGetEquals(MatchFinder *Finder,
|
|||
// might be on global namespace or found by ADL, might be a template, etc.
|
||||
// For now, lets keep a list of known standard types.
|
||||
|
||||
const auto IsAKnownSmartptr =
|
||||
recordDecl(hasAnyName("::std::unique_ptr", "::std::shared_ptr"));
|
||||
const auto IsAKnownSmartptr = recordDecl(
|
||||
anyOf(hasName("::std::unique_ptr"), hasName("::std::shared_ptr")));
|
||||
|
||||
// Matches against nullptr.
|
||||
Finder->addMatcher(
|
||||
binaryOperator(anyOf(hasOperatorName("=="), hasOperatorName("!=")),
|
||||
hasEitherOperand(ignoringImpCasts(
|
||||
anyOf(cxxNullPtrLiteralExpr(), gnuNullExpr(),
|
||||
integerLiteral(equals(0))))),
|
||||
binaryOperator(
|
||||
anyOf(hasOperatorName("=="), hasOperatorName("!=")),
|
||||
hasEitherOperand(ignoringImpCasts(cxxNullPtrLiteralExpr())),
|
||||
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()).
|
||||
// TODO: Catch ptr.get() == other_ptr.get()
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
void RedundantSmartptrGetCheck::registerMatchers(MatchFinder *Finder) {
|
||||
|
@ -111,8 +105,7 @@ bool allReturnTypesMatch(const MatchFinder::MatchResult &Result) {
|
|||
} // namespace
|
||||
|
||||
void RedundantSmartptrGetCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
if (!allReturnTypesMatch(Result))
|
||||
return;
|
||||
if (!allReturnTypesMatch(Result)) return;
|
||||
|
||||
bool IsPtrToPtr = Result.Nodes.getNodeAs<Decl>("ptr_to_ptr") != nullptr;
|
||||
bool IsMemberExpr = Result.Nodes.getNodeAs<Expr>("memberExpr") != nullptr;
|
||||
|
|
|
@ -113,37 +113,6 @@ void Positive() {
|
|||
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
|
||||
// CHECK-MESSAGES: i = *PointerWithOverloadedGet().get();
|
||||
// CHECK-FIXES: i = *PointerWithOverloadedGet();
|
||||
|
||||
bb = std::unique_ptr<int>().get() == NULL;
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
|
||||
// CHECK-MESSAGES: bb = std::unique_ptr<int>().get() == NULL;
|
||||
// CHECK-FIXES: bb = std::unique_ptr<int>() == NULL;
|
||||
bb = ss->get() == NULL;
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
|
||||
// CHECK-MESSAGES: bb = ss->get() == NULL;
|
||||
// CHECK-FIXES: bb = *ss == NULL;
|
||||
|
||||
std::unique_ptr<int> x, y;
|
||||
if (x.get() == nullptr);
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
|
||||
// CHECK-MESSAGES: if (x.get() == nullptr);
|
||||
// CHECK-FIXES: if (x == nullptr);
|
||||
if (nullptr == y.get());
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: redundant get() call
|
||||
// CHECK-MESSAGES: if (nullptr == y.get());
|
||||
// CHECK-FIXES: if (nullptr == y);
|
||||
if (x.get() == NULL);
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
|
||||
// CHECK-MESSAGES: if (x.get() == NULL);
|
||||
// CHECK-FIXES: if (x == NULL);
|
||||
if (NULL == x.get());
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: redundant get() call
|
||||
// CHECK-MESSAGES: if (NULL == x.get());
|
||||
// CHECK-FIXES: if (NULL == x);
|
||||
if (x.get());
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
|
||||
// CHECK-MESSAGES: if (x.get());
|
||||
// CHECK-FIXES: if (x);
|
||||
}
|
||||
|
||||
void Negative() {
|
||||
|
@ -168,5 +137,7 @@ void Negative() {
|
|||
(*Fail2().get()).Do();
|
||||
|
||||
int_ptr ip;
|
||||
bool bb = ip.get() == nullptr;
|
||||
bool bb = std::unique_ptr<int>().get() == NULL;
|
||||
bb = ip.get() == nullptr;
|
||||
bb = u->get() == NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue