-
Notifications
You must be signed in to change notification settings - Fork 14.2k
[clang] NFCI: remove obsolete workaround for template default arguments #94311
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
Conversation
This removes a workaround for template template arguments pointing to older template declarations, which don't have the most recent default argument definition. The removed workaround was introduced in 1abacfc, but #75569 introduced a better fix which is more comprehensive and doesn't require rebuilding TemplateNames.
@llvm/pr-subscribers-clang Author: Matheus Izvekov (mizvekov) ChangesThis removes a workaround for template template arguments pointing to older template declarations, which don't have the most recent default argument definition. The removed workaround was introduced in 1abacfc, but #75569 introduced a better fix which is more comprehensive and doesn't require rebuilding TemplateNames. Full diff: https://github.com/llvm/llvm-project/pull/94311.diff 3 Files Affected:
diff --git a/clang/include/clang/AST/TemplateName.h b/clang/include/clang/AST/TemplateName.h
index 7aedc086ab7d0..489fccb2ef74d 100644
--- a/clang/include/clang/AST/TemplateName.h
+++ b/clang/include/clang/AST/TemplateName.h
@@ -314,11 +314,6 @@ class TemplateName {
TemplateName getUnderlying() const;
- /// Get the template name to substitute when this template name is used as a
- /// template template argument. This refers to the most recent declaration of
- /// the template, including any default template arguments.
- TemplateName getNameToSubstitute() const;
-
TemplateNameDependence getDependence() const;
/// Determines whether this is a dependent template name.
diff --git a/clang/lib/AST/TemplateName.cpp b/clang/lib/AST/TemplateName.cpp
index 3dbdad92813f6..4fc25cb34803e 100644
--- a/clang/lib/AST/TemplateName.cpp
+++ b/clang/lib/AST/TemplateName.cpp
@@ -214,23 +214,6 @@ UsingShadowDecl *TemplateName::getAsUsingShadowDecl() const {
return nullptr;
}
-TemplateName TemplateName::getNameToSubstitute() const {
- TemplateDecl *Decl = getAsTemplateDecl();
-
- // Substituting a dependent template name: preserve it as written.
- if (!Decl)
- return *this;
-
- // If we have a template declaration, use the most recent non-friend
- // declaration of that template.
- Decl = cast<TemplateDecl>(Decl->getMostRecentDecl());
- while (Decl->getFriendObjectKind()) {
- Decl = cast<TemplateDecl>(Decl->getPreviousDecl());
- assert(Decl && "all declarations of template are friends");
- }
- return TemplateName(Decl);
-}
-
TemplateNameDependence TemplateName::getDependence() const {
auto D = TemplateNameDependence::None;
switch (getKind()) {
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index abb8a260faab9..863cc53c55afa 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1856,7 +1856,7 @@ Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
}
- TemplateName Template = Arg.getAsTemplate().getNameToSubstitute();
+ TemplateName Template = Arg.getAsTemplate();
assert(!Template.isNull() && Template.getAsTemplateDecl() &&
"Wrong kind of template template argument");
return Template.getAsTemplateDecl();
@@ -2029,10 +2029,8 @@ TemplateName TemplateInstantiator::TransformTemplateName(
Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
}
- TemplateName Template = Arg.getAsTemplate().getNameToSubstitute();
+ TemplateName Template = Arg.getAsTemplate();
assert(!Template.isNull() && "Null template template argument");
- assert(!Template.getAsQualifiedTemplateName() &&
- "template decl to substitute is qualified?");
if (Final)
return Template;
@@ -2052,8 +2050,8 @@ TemplateName TemplateInstantiator::TransformTemplateName(
if (SubstPack->getFinal())
return Template;
return getSema().Context.getSubstTemplateTemplateParm(
- Template.getNameToSubstitute(), SubstPack->getAssociatedDecl(),
- SubstPack->getIndex(), getPackIndex(Pack));
+ Template, SubstPack->getAssociatedDecl(), SubstPack->getIndex(),
+ getPackIndex(Pack));
}
return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the cleanup, this looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This removes a workaround for template template arguments pointing to older template declarations, which don't have the most recent default argument definition.
The removed workaround was introduced in 1abacfc, but #75569 introduced a better fix which is more comprehensive and doesn't require rebuilding TemplateNames.