Skip to content

[AST] Migrate away from PointerUnion::dyn_cast (NFC) #124674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions clang/include/clang/AST/DeclTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/DeclTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down
Loading