Skip to content

Commit 986581f

Browse files
[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.
1 parent e29c085 commit 986581f

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

clang/include/clang/AST/DeclTemplate.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,8 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
20182018
/// Set the template argument list as written in the sources.
20192019
void
20202020
setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten) {
2021-
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2021+
if (auto *Info =
2022+
dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
20222023
Info->TemplateArgsAsWritten = ArgsWritten;
20232024
else
20242025
ExplicitInfo = ArgsWritten;
@@ -2032,7 +2033,8 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
20322033

20332034
/// Gets the location of the extern keyword, if present.
20342035
SourceLocation getExternKeywordLoc() const {
2035-
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2036+
if (auto *Info =
2037+
dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
20362038
return Info->ExternKeywordLoc;
20372039
return SourceLocation();
20382040
}
@@ -2780,7 +2782,8 @@ class VarTemplateSpecializationDecl : public VarDecl,
27802782
/// Retrieve the template argument list as written in the sources,
27812783
/// if any.
27822784
const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const {
2783-
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2785+
if (auto *Info =
2786+
dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
27842787
return Info->TemplateArgsAsWritten;
27852788
return cast<const ASTTemplateArgumentListInfo *>(ExplicitInfo);
27862789
}
@@ -2803,7 +2806,8 @@ class VarTemplateSpecializationDecl : public VarDecl,
28032806

28042807
/// Gets the location of the extern keyword, if present.
28052808
SourceLocation getExternKeywordLoc() const {
2806-
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2809+
if (auto *Info =
2810+
dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
28072811
return Info->ExternKeywordLoc;
28082812
return SourceLocation();
28092813
}
@@ -2813,7 +2817,8 @@ class VarTemplateSpecializationDecl : public VarDecl,
28132817

28142818
/// Gets the location of the template keyword, if present.
28152819
SourceLocation getTemplateKeywordLoc() const {
2816-
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2820+
if (auto *Info =
2821+
dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
28172822
return Info->TemplateKeywordLoc;
28182823
return SourceLocation();
28192824
}

clang/lib/AST/DeclTemplate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ SourceRange VarTemplateSpecializationDecl::getSourceRange() const {
14961496
}
14971497

14981498
void VarTemplateSpecializationDecl::setExternKeywordLoc(SourceLocation Loc) {
1499-
auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>();
1499+
auto *Info = dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo);
15001500
if (!Info) {
15011501
// Don't allocate if the location is invalid.
15021502
if (Loc.isInvalid())
@@ -1509,7 +1509,7 @@ void VarTemplateSpecializationDecl::setExternKeywordLoc(SourceLocation Loc) {
15091509
}
15101510

15111511
void VarTemplateSpecializationDecl::setTemplateKeywordLoc(SourceLocation Loc) {
1512-
auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>();
1512+
auto *Info = dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo);
15131513
if (!Info) {
15141514
// Don't allocate if the location is invalid.
15151515
if (Loc.isInvalid())

0 commit comments

Comments
 (0)