[clang] 986581f - [AST] Migrate away from PointerUnion::dyn_cast (NFC) (#124674)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 28 10:56:13 PST 2025
Author: Kazu Hirata
Date: 2025-01-28T10:56:09-08:00
New Revision: 986581f6bcef8736c942a9fec9cf12bfbc57c1f6
URL: https://github.com/llvm/llvm-project/commit/986581f6bcef8736c942a9fec9cf12bfbc57c1f6
DIFF: https://github.com/llvm/llvm-project/commit/986581f6bcef8736c942a9fec9cf12bfbc57c1f6.diff
LOG: [AST] Migrate away from PointerUnion::dyn_cast (NFC) (#124674)
Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:
// FIXME: Replace the uses of is(), get() and dyn_cast() with
// isa<T>, cast<T> and the llvm::dyn_cast<T>
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<T*>(ExplicitInfo)
elsewhere in ClassTemplateSpecializationDecl and
VarTemplateSpecializationDecl, meaning that ExplicitInfo is not
guaranteed to be nonnull in those classes.
Added:
Modified:
clang/include/clang/AST/DeclTemplate.h
clang/lib/AST/DeclTemplate.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h
index caaa47d0a297cf..9ecff2c898acd5 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<ExplicitInstantiationInfo *>())
+ if (auto *Info =
+ dyn_cast_if_present<ExplicitInstantiationInfo *>(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<ExplicitInstantiationInfo *>())
+ if (auto *Info =
+ dyn_cast_if_present<ExplicitInstantiationInfo *>(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<ExplicitInstantiationInfo *>())
+ if (auto *Info =
+ dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
return Info->TemplateArgsAsWritten;
return cast<const ASTTemplateArgumentListInfo *>(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<ExplicitInstantiationInfo *>())
+ if (auto *Info =
+ dyn_cast_if_present<ExplicitInstantiationInfo *>(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<ExplicitInstantiationInfo *>())
+ if (auto *Info =
+ dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
return Info->TemplateKeywordLoc;
return SourceLocation();
}
diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index de81bc64106f18..2e1ed9e10713a8 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<ExplicitInstantiationInfo *>();
+ auto *Info = dyn_cast_if_present<ExplicitInstantiationInfo *>(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<ExplicitInstantiationInfo *>();
+ auto *Info = dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo);
if (!Info) {
// Don't allocate if the location is invalid.
if (Loc.isInvalid())
More information about the cfe-commits
mailing list