diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2022-01-11 11:12:12 +0000 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2022-01-11 11:29:38 +0000 |
commit | fba8ad2b719c14e971dfe16458b3d18c08e0e40d (patch) | |
tree | 6c589cb95def1761722e67054195f94d927945a0 | |
parent | 3946095b881366c2f01ebafd18b689337a43aa02 (diff) | |
download | llvm-fba8ad2b719c14e971dfe16458b3d18c08e0e40d.tar.gz |
[SemaTemplateInstantiate] Use cast<> instead of dyn_cast<> to avoid dereference of nullptr
The pointer is always dereferenced immediately below, so assert the cast is correct instead of returning nullptr
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiate.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 7d4c000e7e90..7c6bb4c8a5f8 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -2790,11 +2790,10 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, CurrentInstantiationScope = I->Scope; // Allow 'this' within late-parsed attributes. - NamedDecl *ND = dyn_cast<NamedDecl>(I->NewDecl); - CXXRecordDecl *ThisContext = - dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext()); + auto *ND = cast<NamedDecl>(I->NewDecl); + auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext()); CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(), - ND && ND->isCXXInstanceMember()); + ND->isCXXInstanceMember()); Attr *NewAttr = instantiateTemplateAttribute(I->TmplAttr, Context, *this, TemplateArgs); |