diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -551,11 +551,12 @@ LateAttrs->push_back(LateInstantiatedAttribute(TmplAttr, Saved, New)); } else { // Allow 'this' within late-parsed attributes. - NamedDecl *ND = dyn_cast(New); - CXXRecordDecl *ThisContext = - dyn_cast_or_null(ND->getDeclContext()); - CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(), - ND && ND->isCXXInstanceMember()); + if (NamedDecl *ND = dyn_cast(New)) { + CXXRecordDecl *ThisContext = + dyn_cast_or_null(ND->getDeclContext()); + CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(), + ND->isCXXInstanceMember()); + } Attr *NewAttr = sema::instantiateTemplateAttribute(TmplAttr, Context, *this, TemplateArgs);