Commit 86497026 authored by Simon Pilgrim's avatar Simon Pilgrim
Browse files

[clang-tidy] Use cast<>/castAs<> instead of dyn_cast<>/getAs<> to avoid dereference of nullptr

The pointer is dereferenced immediately, so assert the cast is correct instead of returning nullptr
parent 946f2902
......@@ -192,7 +192,7 @@ void DurationFactoryScaleCheck::check(const MatchFinder::MatchResult &Result) {
Result.Nodes.getNodeAs<BinaryOperator>("div_binop")) {
// We next handle division.
// For division, we only check the RHS.
const auto *FloatLit = llvm::dyn_cast<FloatingLiteral>(DivBinOp->getRHS());
const auto *FloatLit = llvm::cast<FloatingLiteral>(DivBinOp->getRHS());
llvm::Optional<DurationScale> NewScale =
getNewScale(Scale, 1.0 / FloatLit->getValueAsApproximateDouble());
......
......@@ -413,9 +413,9 @@ static bool areTypesCompatible(QualType ArgType, QualType ParamType,
// Arithmetic types are interconvertible, except scoped enums.
if (ParamType->isArithmeticType() && ArgType->isArithmeticType()) {
if ((ParamType->isEnumeralType() &&
ParamType->getAs<EnumType>()->getDecl()->isScoped()) ||
ParamType->castAs<EnumType>()->getDecl()->isScoped()) ||
(ArgType->isEnumeralType() &&
ArgType->getAs<EnumType>()->getDecl()->isScoped()))
ArgType->castAs<EnumType>()->getDecl()->isScoped()))
return false;
return true;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment