From 5e4bf8292ef0531f2b1aab45e3e4ee2b1d53527e Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Mon, 27 Jan 2025 11:46:26 -0800 Subject: [PATCH] [AST] Migrate away from PointerUnion::dyn_cast (NFC) Note that PointerUnion::dyn_cast has been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa, cast and the llvm::dyn_cast This patch migrates uses of PointerUnion::dyn_cast to dyn_cast_if_present (see the definition of PointerUnion::dyn_cast). Note that we already have dyn_cast_if_present(ExplicitInfo) elsewhere in ClassTemplateSpecializationDecl and VarTemplateSpecializationDecl, meaning that ExplicitInfo is not guaranteed to be nonnull in those classes. --- clang/include/clang/AST/DeclTemplate.h | 15 ++++++++++----- clang/lib/AST/DeclTemplate.cpp | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) 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())