Skip to content

Commit

Permalink
Use isa and isa_and_nonnull when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-cukic committed Feb 7, 2023
1 parent 05d4020 commit 24e7eed
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ContextUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static std::string nameForContext(DeclContext *context)
return rec->getNameAsString();
} else if (auto *method = dyn_cast<CXXMethodDecl>(context)) {
return method->getNameAsString();
} else if (dyn_cast<TranslationUnitDecl>(context)) {
} else if (isa<TranslationUnitDecl>(context)) {
return {};
} else {
llvm::errs() << "Unhandled kind: " << context->getDeclKindName() << "\n";
Expand Down
2 changes: 1 addition & 1 deletion src/ContextUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace clazy
inline bool isValueDeclInFunctionContext(const clang::ValueDecl *valueDecl)
{
const auto *context = valueDecl ? valueDecl->getDeclContext() : nullptr;
return context && llvm::isa<clang::FunctionDecl>(context) && !llvm::isa<clang::ParmVarDecl>(valueDecl);
return llvm::isa_and_nonnull<clang::FunctionDecl>(context) && !llvm::isa<clang::ParmVarDecl>(valueDecl);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/checks/level0/strict-iterators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ bool StrictIterators::handleImplicitCast(ImplicitCastExpr *implicitCast)
}

auto *p = m_context->parentMap->getParent(implicitCast);
if (dyn_cast<CXXOperatorCallExpr>(p)) {
if (isa<CXXOperatorCallExpr>(p)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/checks/level0/temporary-iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void TemporaryIterator::VisitStmt(clang::Stmt *stm)
}

Stmt *firstChild = clazy::getFirstChild(impl);
if (firstChild && isa<ImplicitCastExpr>(firstChild) && dyn_cast<ImplicitCastExpr>(firstChild)->getCastKind() == CK_LValueToRValue) {
if (isa_and_nonnull<ImplicitCastExpr>(firstChild) && dyn_cast<ImplicitCastExpr>(firstChild)->getCastKind() == CK_LValueToRValue) {
return;
}
}
Expand Down

0 comments on commit 24e7eed

Please sign in to comment.