Skip to content

Commit 691223b

Browse files
committed
[clang] Replace X && isa<Y>(X) with isa_and_nonnull<Y>(X). NFC
This addresses a clang-tidy suggestion.
1 parent cc8fa1e commit 691223b

29 files changed

+52
-48
lines changed

clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ class CapabilityExpr {
330330

331331
bool shouldIgnore() const { return sexpr() == nullptr; }
332332

333-
bool isInvalid() const { return sexpr() && isa<til::Undefined>(sexpr()); }
333+
bool isInvalid() const { return isa_and_nonnull<til::Undefined>(sexpr()); }
334334

335-
bool isUniversal() const { return sexpr() && isa<til::Wildcard>(sexpr()); }
335+
bool isUniversal() const { return isa_and_nonnull<til::Wildcard>(sexpr()); }
336336
};
337337

338338
// Translate clang::Expr to til::SExpr.

clang/include/clang/Lex/Preprocessor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ class Preprocessor {
13601360

13611361
MacroState &S = CurSubmoduleState->Macros[II];
13621362
auto *MD = S.getLatest();
1363-
while (MD && isa<VisibilityMacroDirective>(MD))
1363+
while (isa_and_nonnull<VisibilityMacroDirective>(MD))
13641364
MD = MD->getPrevious();
13651365
return MacroDefinition(dyn_cast_or_null<DefMacroDirective>(MD),
13661366
S.getActiveModuleMacros(*this, II),

clang/include/clang/Sema/SemaObjC.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class SemaObjC : public SemaBase {
383383
void AddAnyMethodToGlobalPool(Decl *D);
384384

385385
void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
386-
bool isObjCMethodDecl(Decl *D) { return D && isa<ObjCMethodDecl>(D); }
386+
bool isObjCMethodDecl(Decl *D) { return isa_and_nonnull<ObjCMethodDecl>(D); }
387387

388388
/// CheckImplementationIvars - This routine checks if the instance variables
389389
/// listed in the implelementation match those listed in the interface.

clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ class SymbolicRegion : public SubRegion {
781781
: SubRegion(sreg, SymbolicRegionKind), sym(s) {
782782
// Because pointer arithmetic is represented by ElementRegion layers,
783783
// the base symbol here should not contain any arithmetic.
784-
assert(s && isa<SymbolData>(s));
784+
assert(isa_and_nonnull<SymbolData>(s));
785785
assert(s->getType()->isAnyPointerType() ||
786786
s->getType()->isReferenceType() ||
787787
s->getType()->isBlockPointerType());

clang/lib/ARCMigrate/TransUnbridgedCasts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ class UnbridgedCastRewriter : public RecursiveASTVisitor<UnbridgedCastRewriter>{
371371
Stmt *parent = E;
372372
do {
373373
parent = StmtMap->getParentIgnoreParenImpCasts(parent);
374-
} while (parent && isa<FullExpr>(parent));
374+
} while (isa_and_nonnull<FullExpr>(parent));
375375

376376
if (ReturnStmt *retS = dyn_cast_or_null<ReturnStmt>(parent)) {
377377
std::string note = "remove the cast and change return type of function "

clang/lib/AST/ASTImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ ExpectedType ASTNodeImporter::VisitInjectedClassNameType(
15051505
// The InjectedClassNameType is created in VisitRecordDecl when the
15061506
// T->getDecl() is imported. Here we can return the existing type.
15071507
const Type *Ty = (*ToDeclOrErr)->getTypeForDecl();
1508-
assert(Ty && isa<InjectedClassNameType>(Ty));
1508+
assert(isa_and_nonnull<InjectedClassNameType>(Ty));
15091509
return QualType(Ty, 0);
15101510
}
15111511

clang/lib/AST/DeclBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ bool Decl::isInExportDeclContext() const {
11161116
while (DC && !isa<ExportDecl>(DC))
11171117
DC = DC->getLexicalParent();
11181118

1119-
return DC && isa<ExportDecl>(DC);
1119+
return isa_and_nonnull<ExportDecl>(DC);
11201120
}
11211121

11221122
bool Decl::isInAnotherModuleUnit() const {

clang/lib/AST/Expr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK,
837837
typedef SmallVector<const ClassTemplateSpecializationDecl *, 8> SpecsTy;
838838
SpecsTy Specs;
839839
const DeclContext *Ctx = FD->getDeclContext();
840-
while (Ctx && isa<NamedDecl>(Ctx)) {
840+
while (isa_and_nonnull<NamedDecl>(Ctx)) {
841841
const ClassTemplateSpecializationDecl *Spec
842842
= dyn_cast<ClassTemplateSpecializationDecl>(Ctx);
843843
if (Spec && !Spec->isExplicitSpecialization())
@@ -3067,7 +3067,7 @@ Expr *Expr::IgnoreParenCasts() {
30673067

30683068
Expr *Expr::IgnoreConversionOperatorSingleStep() {
30693069
if (auto *MCE = dyn_cast<CXXMemberCallExpr>(this)) {
3070-
if (MCE->getMethodDecl() && isa<CXXConversionDecl>(MCE->getMethodDecl()))
3070+
if (isa_and_nonnull<CXXConversionDecl>(MCE->getMethodDecl()))
30713071
return MCE->getImplicitObjectArgument();
30723072
}
30733073
return this;

clang/lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,7 @@ static bool IsWeakLValue(const LValue &Value) {
21302130

21312131
static bool isZeroSized(const LValue &Value) {
21322132
const ValueDecl *Decl = GetLValueBaseDecl(Value);
2133-
if (Decl && isa<VarDecl>(Decl)) {
2133+
if (isa_and_nonnull<VarDecl>(Decl)) {
21342134
QualType Ty = Decl->getType();
21352135
if (Ty->isArrayType())
21362136
return Ty->isIncompleteType() ||

clang/lib/AST/Mangle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ void MangleContext::mangleBlock(const DeclContext *DC, const BlockDecl *BD,
302302
assert((isa<NamedDecl>(DC) || isa<BlockDecl>(DC)) &&
303303
"expected a NamedDecl or BlockDecl");
304304
if (isa<BlockDecl>(DC))
305-
for (; DC && isa<BlockDecl>(DC); DC = DC->getParent())
305+
for (; isa_and_nonnull<BlockDecl>(DC); DC = DC->getParent())
306306
(void) getBlockId(cast<BlockDecl>(DC), true);
307307
assert((isa<TranslationUnitDecl>(DC) || isa<NamedDecl>(DC)) &&
308308
"expected a TranslationUnitDecl or a NamedDecl");

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2748,7 +2748,7 @@ void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T,
27482748
return;
27492749
}
27502750
Out << '@';
2751-
} else if (IsInLambda && D && isa<CXXConversionDecl>(D)) {
2751+
} else if (IsInLambda && isa_and_nonnull<CXXConversionDecl>(D)) {
27522752
// The only lambda conversion operators are to function pointers, which
27532753
// can differ by their calling convention and are typically deduced. So
27542754
// we make sure that this type gets mangled properly.

clang/lib/AST/ParentMap.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ Stmt* ParentMap::getParent(Stmt* S) const {
139139
}
140140

141141
Stmt *ParentMap::getParentIgnoreParens(Stmt *S) const {
142-
do { S = getParent(S); } while (S && isa<ParenExpr>(S));
142+
do {
143+
S = getParent(S);
144+
} while (isa_and_nonnull<ParenExpr>(S));
143145
return S;
144146
}
145147

@@ -155,7 +157,8 @@ Stmt *ParentMap::getParentIgnoreParenCasts(Stmt *S) const {
155157
Stmt *ParentMap::getParentIgnoreParenImpCasts(Stmt *S) const {
156158
do {
157159
S = getParent(S);
158-
} while (S && isa<Expr>(S) && cast<Expr>(S)->IgnoreParenImpCasts() != S);
160+
} while (isa_and_nonnull<Expr>(S) &&
161+
cast<Expr>(S)->IgnoreParenImpCasts() != S);
159162

160163
return S;
161164
}

clang/lib/AST/StmtPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ namespace {
8484

8585
void PrintStmt(Stmt *S, int SubIndent) {
8686
IndentLevel += SubIndent;
87-
if (S && isa<Expr>(S)) {
87+
if (isa_and_nonnull<Expr>(S)) {
8888
// If this is an expr used in a stmt context, indent and newline it.
8989
Indent();
9090
Visit(S);
@@ -1939,7 +1939,7 @@ void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) {
19391939
void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) {
19401940
// If we have a conversion operator call only print the argument.
19411941
CXXMethodDecl *MD = Node->getMethodDecl();
1942-
if (MD && isa<CXXConversionDecl>(MD)) {
1942+
if (isa_and_nonnull<CXXConversionDecl>(MD)) {
19431943
PrintExpr(Node->getImplicitObjectArgument());
19441944
return;
19451945
}

clang/lib/Analysis/UnsafeBufferUsage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2772,7 +2772,7 @@ fixVariable(const VarDecl *VD, FixitStrategy::Kind K,
27722772
// also covers call-operator of lamdas
27732773
isa<CXXMethodDecl>(FD) ||
27742774
// skip when the function body is a try-block
2775-
(FD->hasBody() && isa<CXXTryStmt>(FD->getBody())) ||
2775+
isa_and_nonnull<CXXTryStmt>(FD->getBody()) ||
27762776
FD->isOverloadedOperator()) {
27772777
DEBUG_NOTE_DECL_FAIL(VD, " : unsupported function decl");
27782778
return {}; // TODO test all these cases

clang/lib/CodeGen/CGBlocks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ static void computeBlockInfo(CodeGenModule &CGM, CodeGenFunction *CGF,
577577

578578
// First, 'this'.
579579
if (block->capturesCXXThis()) {
580-
assert(CGF && CGF->CurFuncDecl && isa<CXXMethodDecl>(CGF->CurFuncDecl) &&
580+
assert(CGF && isa_and_nonnull<CXXMethodDecl>(CGF->CurFuncDecl) &&
581581
"Can't capture 'this' outside a method");
582582
QualType thisType = cast<CXXMethodDecl>(CGF->CurFuncDecl)->getThisType();
583583

clang/lib/CodeGen/CGClass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ void CodeGenFunction::EmitConstructorBody(FunctionArgList &Args) {
859859

860860
// Enter the function-try-block before the constructor prologue if
861861
// applicable.
862-
bool IsTryBody = (Body && isa<CXXTryStmt>(Body));
862+
bool IsTryBody = isa_and_nonnull<CXXTryStmt>(Body);
863863
if (IsTryBody)
864864
EnterCXXTryStmt(*cast<CXXTryStmt>(Body), true);
865865

@@ -1475,7 +1475,7 @@ void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) {
14751475

14761476
// If the body is a function-try-block, enter the try before
14771477
// anything else.
1478-
bool isTryBody = (Body && isa<CXXTryStmt>(Body));
1478+
bool isTryBody = isa_and_nonnull<CXXTryStmt>(Body);
14791479
if (isTryBody)
14801480
EnterCXXTryStmt(*cast<CXXTryStmt>(Body), true);
14811481
EmitAsanPrologueOrEpilogue(false);

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ bool ConstStructBuilder::Build(const InitListExpr *ILE, bool AllowOverwrite) {
715715
const Expr *Init = nullptr;
716716
if (ElementNo < ILE->getNumInits())
717717
Init = ILE->getInit(ElementNo++);
718-
if (Init && isa<NoInitExpr>(Init))
718+
if (isa_and_nonnull<NoInitExpr>(Init))
719719
continue;
720720

721721
// Zero-sized fields are not emitted, but their initializers may still

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8510,7 +8510,8 @@ class MappableExprsHandler {
85108510
assert(VDecl == VD && "We got information for the wrong declaration??");
85118511
assert(!Components.empty() &&
85128512
"Not expecting declaration with no component lists.");
8513-
if (VD && E && VD->getType()->isAnyPointerType() && isa<DeclRefExpr>(E))
8513+
if (VD && VD->getType()->isAnyPointerType() &&
8514+
isa_and_nonnull<DeclRefExpr>(E))
85148515
HasMapBasePtr = true;
85158516
if (VD && E && VD->getType()->isAnyPointerType() &&
85168517
(isa<ArraySectionExpr>(E) || isa<ArraySubscriptExpr>(E)))

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class OMPLexicalScope : public CodeGenFunction::LexicalScope {
7272
static bool isCapturedVar(CodeGenFunction &CGF, const VarDecl *VD) {
7373
return CGF.LambdaCaptureFields.lookup(VD) ||
7474
(CGF.CapturedStmtInfo && CGF.CapturedStmtInfo->lookup(VD)) ||
75-
(CGF.CurCodeDecl && isa<BlockDecl>(CGF.CurCodeDecl) &&
75+
(isa_and_nonnull<BlockDecl>(CGF.CurCodeDecl) &&
7676
cast<BlockDecl>(CGF.CurCodeDecl)->capturesVariable(VD));
7777
}
7878

@@ -227,7 +227,7 @@ class OMPSimdLexicalScope : public CodeGenFunction::LexicalScope {
227227
static bool isCapturedVar(CodeGenFunction &CGF, const VarDecl *VD) {
228228
return CGF.LambdaCaptureFields.lookup(VD) ||
229229
(CGF.CapturedStmtInfo && CGF.CapturedStmtInfo->lookup(VD)) ||
230-
(CGF.CurCodeDecl && isa<BlockDecl>(CGF.CurCodeDecl) &&
230+
(isa_and_nonnull<BlockDecl>(CGF.CurCodeDecl) &&
231231
cast<BlockDecl>(CGF.CurCodeDecl)->capturesVariable(VD));
232232
}
233233

@@ -315,7 +315,7 @@ LValue CodeGenFunction::EmitOMPSharedLValue(const Expr *E) {
315315
bool IsCaptured =
316316
LambdaCaptureFields.lookup(OrigVD) ||
317317
(CapturedStmtInfo && CapturedStmtInfo->lookup(OrigVD)) ||
318-
(CurCodeDecl && isa<BlockDecl>(CurCodeDecl));
318+
(isa_and_nonnull<BlockDecl>(CurCodeDecl));
319319
DeclRefExpr DRE(getContext(), const_cast<VarDecl *>(OrigVD), IsCaptured,
320320
OrigDRE->getType(), VK_LValue, OrigDRE->getExprLoc());
321321
return EmitLValue(&DRE);

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2951,7 +2951,7 @@ void CodeGenFunction::emitAlignmentAssumptionCheck(
29512951
SourceLocation SecondaryLoc, llvm::Value *Alignment,
29522952
llvm::Value *OffsetValue, llvm::Value *TheCheck,
29532953
llvm::Instruction *Assumption) {
2954-
assert(Assumption && isa<llvm::CallInst>(Assumption) &&
2954+
assert(isa_and_nonnull<llvm::CallInst>(Assumption) &&
29552955
cast<llvm::CallInst>(Assumption)->getCalledOperand() ==
29562956
llvm::Intrinsic::getDeclaration(
29572957
Builder.GetInsertBlock()->getParent()->getParent(),

clang/lib/Index/IndexBody.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
268268
}
269269
return true;
270270
};
271-
bool IsPropCall = Containing && isa<PseudoObjectExpr>(Containing);
271+
bool IsPropCall = isa_and_nonnull<PseudoObjectExpr>(Containing);
272272
// Implicit property message sends are not 'implicit'.
273273
if ((E->isImplicit() || IsPropCall) &&
274274
!(IsPropCall &&

clang/lib/Lex/PPMacroExpansion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void Preprocessor::updateModuleMacroInfo(const IdentifierInfo *II,
226226
bool IsSystemMacro = true;
227227
bool IsAmbiguous = false;
228228
if (auto *MD = Info.MD) {
229-
while (MD && isa<VisibilityMacroDirective>(MD))
229+
while (isa_and_nonnull<VisibilityMacroDirective>(MD))
230230
MD = MD->getPrevious();
231231
if (auto *DMD = dyn_cast_or_null<DefMacroDirective>(MD)) {
232232
MI = DMD->getInfo();

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ static ControlFlowKind CheckFallThrough(AnalysisDeclContext &AC) {
442442
if (!live[B->getBlockID()]) {
443443
if (B->pred_begin() == B->pred_end()) {
444444
const Stmt *Term = B->getTerminatorStmt();
445-
if (Term && isa<CXXTryStmt>(Term))
445+
if (isa_and_nonnull<CXXTryStmt>(Term))
446446
// When not adding EH edges from calls, catch clauses
447447
// can otherwise seem dead. Avoid noting them as dead.
448448
count += reachable_code::ScanReachableFromBlock(B, live);
@@ -1100,7 +1100,7 @@ namespace {
11001100
// issue a warn_fallthrough_attr_unreachable for them.
11011101
for (const auto *B : *Cfg) {
11021102
const Stmt *L = B->getLabel();
1103-
if (L && isa<SwitchCase>(L) && ReachableBlocks.insert(B).second)
1103+
if (isa_and_nonnull<SwitchCase>(L) && ReachableBlocks.insert(B).second)
11041104
BlockQueue.push_back(B);
11051105
}
11061106

@@ -1128,7 +1128,7 @@ namespace {
11281128
if (!P) continue;
11291129

11301130
const Stmt *Term = P->getTerminatorStmt();
1131-
if (Term && isa<SwitchStmt>(Term))
1131+
if (isa_and_nonnull<SwitchStmt>(Term))
11321132
continue; // Switch statement, good.
11331133

11341134
const SwitchCase *SW = dyn_cast_or_null<SwitchCase>(P->getLabel());
@@ -1327,7 +1327,7 @@ static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC,
13271327
B = *B->succ_begin();
13281328
Term = B->getTerminatorStmt();
13291329
}
1330-
if (!(B->empty() && Term && isa<BreakStmt>(Term))) {
1330+
if (!(B->empty() && isa_and_nonnull<BreakStmt>(Term))) {
13311331
Preprocessor &PP = S.getPreprocessor();
13321332
StringRef AnnotationSpelling = getFallthroughAttrSpelling(PP, L);
13331333
SmallString<64> TextToInsert(AnnotationSpelling);

clang/lib/Sema/SemaCXXScopeSpec.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ bool Sema::ActOnCXXNestedNameSpecifier(Scope *S,
974974
R.setBegin(SS.getRange().getBegin());
975975

976976
Diag(CCLoc, diag::err_non_type_template_in_nested_name_specifier)
977-
<< (TD && isa<VarTemplateDecl>(TD)) << Template << R;
977+
<< isa_and_nonnull<VarTemplateDecl>(TD) << Template << R;
978978
NoteAllFoundTemplates(Template);
979979
return true;
980980
}

clang/lib/Sema/SemaChecking.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3839,11 +3839,11 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
38393839
if (CallType != VariadicDoesNotApply &&
38403840
(!FD || FD->getBuiltinID() != Builtin::BI__noop)) {
38413841
unsigned NumParams = Proto ? Proto->getNumParams()
3842-
: FDecl && isa<FunctionDecl>(FDecl)
3843-
? cast<FunctionDecl>(FDecl)->getNumParams()
3844-
: FDecl && isa<ObjCMethodDecl>(FDecl)
3845-
? cast<ObjCMethodDecl>(FDecl)->param_size()
3846-
: 0;
3842+
: isa_and_nonnull<FunctionDecl>(FDecl)
3843+
? cast<FunctionDecl>(FDecl)->getNumParams()
3844+
: isa_and_nonnull<ObjCMethodDecl>(FDecl)
3845+
? cast<ObjCMethodDecl>(FDecl)->param_size()
3846+
: 0;
38473847

38483848
for (unsigned ArgIdx = NumParams; ArgIdx < Args.size(); ++ArgIdx) {
38493849
// Args[ArgIdx] can be null in malformed code.

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,7 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool UseGlobal,
20742074
if (DirectInitRange.isValid()) {
20752075
assert(Initializer && "Have parens but no initializer.");
20762076
InitStyle = CXXNewInitializationStyle::Parens;
2077-
} else if (Initializer && isa<InitListExpr>(Initializer))
2077+
} else if (isa_and_nonnull<InitListExpr>(Initializer))
20782078
InitStyle = CXXNewInitializationStyle::Braces;
20792079
else {
20802080
assert((!Initializer || isa<ImplicitValueInitExpr>(Initializer) ||
@@ -3823,7 +3823,7 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
38233823

38243824
// Otherwise, the usual operator delete[] should be the
38253825
// function we just found.
3826-
else if (OperatorDelete && isa<CXXMethodDecl>(OperatorDelete))
3826+
else if (isa_and_nonnull<CXXMethodDecl>(OperatorDelete))
38273827
UsualArrayDeleteWantsSize =
38283828
UsualDeallocFnInfo(*this,
38293829
DeclAccessPair::make(OperatorDelete, AS_public))
@@ -8595,7 +8595,7 @@ static void CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures(
85958595
assert(S.CurContext->isDependentContext());
85968596
#ifndef NDEBUG
85978597
DeclContext *DC = S.CurContext;
8598-
while (DC && isa<CapturedDecl>(DC))
8598+
while (isa_and_nonnull<CapturedDecl>(DC))
85998599
DC = DC->getParent();
86008600
assert(
86018601
CurrentLSI->CallOperator == DC &&
@@ -9172,7 +9172,7 @@ ExprResult Sema::ActOnFinishFullExpr(Expr *FE, SourceLocation CC,
91729172
// - Teach the handful of places that iterate over FunctionScopes to
91739173
// stop at the outermost enclosing lexical scope."
91749174
DeclContext *DC = CurContext;
9175-
while (DC && isa<CapturedDecl>(DC))
9175+
while (isa_and_nonnull<CapturedDecl>(DC))
91769176
DC = DC->getParent();
91779177
const bool IsInLambdaDeclContext = isLambdaCallOperator(DC);
91789178
if (IsInLambdaDeclContext && CurrentLSI &&

clang/lib/Sema/SemaInit.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,7 @@ void InitListChecker::CheckStructUnionTypes(
21942194

21952195
// Designated inits always initialize fields, so if we see one, all
21962196
// remaining base classes have no explicit initializer.
2197-
if (Init && isa<DesignatedInitExpr>(Init))
2197+
if (isa_and_nonnull<DesignatedInitExpr>(Init))
21982198
Init = nullptr;
21992199

22002200
// C++ [over.match.class.deduct]p1.6:
@@ -6350,7 +6350,7 @@ void InitializationSequence::InitializeFrom(Sema &S,
63506350
// class member of array type from a parenthesized initializer list.
63516351
else if (S.getLangOpts().CPlusPlus &&
63526352
Entity.getKind() == InitializedEntity::EK_Member &&
6353-
Initializer && isa<InitListExpr>(Initializer)) {
6353+
isa_and_nonnull<InitListExpr>(Initializer)) {
63546354
TryListInitialization(S, Entity, Kind, cast<InitListExpr>(Initializer),
63556355
*this, TreatUnavailableAsInvalid);
63566356
AddParenthesizedArrayInitStep(DestType);
@@ -8793,7 +8793,7 @@ ExprResult InitializationSequence::Perform(Sema &S,
87938793
// constant expressions here in order to perform narrowing checks =(
87948794
EnterExpressionEvaluationContext Evaluated(
87958795
S, EnterExpressionEvaluationContext::InitList,
8796-
CurInit.get() && isa<InitListExpr>(CurInit.get()));
8796+
isa_and_nonnull<InitListExpr>(CurInit.get()));
87978797

87988798
// C++ [class.abstract]p2:
87998799
// no objects of an abstract class can be created except as subobjects

clang/lib/Sema/SemaStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3701,7 +3701,7 @@ bool Sema::DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD,
37013701
if (isLambdaConversionOperator(FD))
37023702
return false;
37033703

3704-
if (RetExpr && isa<InitListExpr>(RetExpr)) {
3704+
if (isa_and_nonnull<InitListExpr>(RetExpr)) {
37053705
// If the deduction is for a return statement and the initializer is
37063706
// a braced-init-list, the program is ill-formed.
37073707
Diag(RetExpr->getExprLoc(),

0 commit comments

Comments
 (0)