Skip to content

Commit fba8ad2

Browse files
committed
[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
1 parent 3946095 commit fba8ad2

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,11 +2790,10 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation,
27902790
CurrentInstantiationScope = I->Scope;
27912791

27922792
// Allow 'this' within late-parsed attributes.
2793-
NamedDecl *ND = dyn_cast<NamedDecl>(I->NewDecl);
2794-
CXXRecordDecl *ThisContext =
2795-
dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
2793+
auto *ND = cast<NamedDecl>(I->NewDecl);
2794+
auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
27962795
CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(),
2797-
ND && ND->isCXXInstanceMember());
2796+
ND->isCXXInstanceMember());
27982797

27992798
Attr *NewAttr =
28002799
instantiateTemplateAttribute(I->TmplAttr, Context, *this, TemplateArgs);

0 commit comments

Comments
 (0)