From 5d1e3ed3e257535fbd51706023685d2c2d9eba51 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Sat, 12 Feb 2022 19:59:13 +0000 Subject: [PATCH] [clang-tidy] SimplifyBooleanExprCheck - use cast<> instead of dyn_cast<> to avoid dereference of nullptr The IfStmt pointer is always referenced inside the replaceCompoundReturnWithCondition call, so assert the cast is correct instead of returning nullptr --- .../clang-tidy/readability/SimplifyBooleanExprCheck.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp index 9c2ddf139a12..61ba4b857636 100644 --- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp @@ -750,7 +750,7 @@ void SimplifyBooleanExprCheck::replaceCompoundReturnWithCondition( void SimplifyBooleanExprCheck::replaceCaseCompoundReturnWithCondition( const MatchFinder::MatchResult &Result, bool Negated) { const auto *CaseDefault = Result.Nodes.getNodeAs(CaseId); - const auto *If = dyn_cast(CaseDefault->getSubStmt()); + const auto *If = cast(CaseDefault->getSubStmt()); replaceCompoundReturnWithCondition(Result, Negated, If); } @@ -758,14 +758,14 @@ void SimplifyBooleanExprCheck::replaceDefaultCompoundReturnWithCondition( const MatchFinder::MatchResult &Result, bool Negated) { const SwitchCase *CaseDefault = Result.Nodes.getNodeAs(DefaultId); - const auto *If = dyn_cast(CaseDefault->getSubStmt()); + const auto *If = cast(CaseDefault->getSubStmt()); replaceCompoundReturnWithCondition(Result, Negated, If); } void SimplifyBooleanExprCheck::replaceLabelCompoundReturnWithCondition( const MatchFinder::MatchResult &Result, bool Negated) { const auto *Label = Result.Nodes.getNodeAs(LabelId); - const auto *If = dyn_cast(Label->getSubStmt()); + const auto *If = cast(Label->getSubStmt()); replaceCompoundReturnWithCondition(Result, Negated, If); }