diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index caaa47d0a297c..9ecff2c898acd 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -2018,7 +2018,8 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, /// Set the template argument list as written in the sources. void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten) { - if (auto *Info = ExplicitInfo.dyn_cast()) + if (auto *Info = + dyn_cast_if_present(ExplicitInfo)) Info->TemplateArgsAsWritten = ArgsWritten; else ExplicitInfo = ArgsWritten; @@ -2032,7 +2033,8 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, /// Gets the location of the extern keyword, if present. SourceLocation getExternKeywordLoc() const { - if (auto *Info = ExplicitInfo.dyn_cast()) + if (auto *Info = + dyn_cast_if_present(ExplicitInfo)) return Info->ExternKeywordLoc; return SourceLocation(); } @@ -2780,7 +2782,8 @@ class VarTemplateSpecializationDecl : public VarDecl, /// Retrieve the template argument list as written in the sources, /// if any. const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const { - if (auto *Info = ExplicitInfo.dyn_cast()) + if (auto *Info = + dyn_cast_if_present(ExplicitInfo)) return Info->TemplateArgsAsWritten; return cast(ExplicitInfo); } @@ -2803,7 +2806,8 @@ class VarTemplateSpecializationDecl : public VarDecl, /// Gets the location of the extern keyword, if present. SourceLocation getExternKeywordLoc() const { - if (auto *Info = ExplicitInfo.dyn_cast()) + if (auto *Info = + dyn_cast_if_present(ExplicitInfo)) return Info->ExternKeywordLoc; return SourceLocation(); } @@ -2813,7 +2817,8 @@ class VarTemplateSpecializationDecl : public VarDecl, /// Gets the location of the template keyword, if present. SourceLocation getTemplateKeywordLoc() const { - if (auto *Info = ExplicitInfo.dyn_cast()) + if (auto *Info = + dyn_cast_if_present(ExplicitInfo)) return Info->TemplateKeywordLoc; return SourceLocation(); } diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index de81bc64106f1..2e1ed9e10713a 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -1496,7 +1496,7 @@ SourceRange VarTemplateSpecializationDecl::getSourceRange() const { } void VarTemplateSpecializationDecl::setExternKeywordLoc(SourceLocation Loc) { - auto *Info = ExplicitInfo.dyn_cast(); + auto *Info = dyn_cast_if_present(ExplicitInfo); if (!Info) { // Don't allocate if the location is invalid. if (Loc.isInvalid()) @@ -1509,7 +1509,7 @@ void VarTemplateSpecializationDecl::setExternKeywordLoc(SourceLocation Loc) { } void VarTemplateSpecializationDecl::setTemplateKeywordLoc(SourceLocation Loc) { - auto *Info = ExplicitInfo.dyn_cast(); + auto *Info = dyn_cast_if_present(ExplicitInfo); if (!Info) { // Don't allocate if the location is invalid. if (Loc.isInvalid())