[clang] e0acfed - Clean up handling of constrained parameters in lambdas.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Wed May 12 18:45:53 PDT 2021
Author: Richard Smith
Date: 2021-05-12T18:45:33-07:00
New Revision: e0acfed7ed5173b437868f75fc394084487e390a
URL: https://github.com/llvm/llvm-project/commit/e0acfed7ed5173b437868f75fc394084487e390a
DIFF: https://github.com/llvm/llvm-project/commit/e0acfed7ed5173b437868f75fc394084487e390a.diff
LOG: Clean up handling of constrained parameters in lambdas.
No functionality change intended.
Added:
Modified:
clang/lib/AST/TypePrinter.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/TreeTransform.h
Removed:
################################################################################
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 59549dbfba2b..748a48f8eca4 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1125,7 +1125,9 @@ void TypePrinter::printAutoBefore(const AutoType *T, raw_ostream &OS) {
printBefore(T->getDeducedType(), OS);
} else {
if (T->isConstrained()) {
- OS << T->getTypeConstraintConcept()->getName();
+ // FIXME: Track a TypeConstraint as type sugar, so that we can print the
+ // type as it was written.
+ T->getTypeConstraintConcept()->getDeclName().print(OS, Policy);
auto Args = T->getTypeConstraintArguments();
if (!Args.empty())
printTemplateArgumentList(
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a4cbb2e8e9d5..cfafd423fa5f 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2386,10 +2386,10 @@ ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm,
}
if (AttachTypeConstraint(
TC->getNestedNameSpecifierLoc(), TC->getConceptNameInfo(),
- TC->getNamedConcept(), &InstArgs, Inst,
+ TC->getNamedConcept(), TemplArgInfo ? &InstArgs : nullptr, Inst,
TTP->isParameterPack()
? cast<CXXFoldExpr>(TC->getImmediatelyDeclaredConstraint())
- ->getEllipsisLoc()
+ ->getEllipsisLoc()
: SourceLocation()))
return nullptr;
}
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 1d572054e5fb..cbd29701496b 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2581,7 +2581,6 @@ Decl *TemplateDeclInstantiator::VisitParmVarDecl(ParmVarDecl *D) {
Decl *TemplateDeclInstantiator::VisitTemplateTypeParmDecl(
TemplateTypeParmDecl *D) {
- // TODO: don't always clone when decls are refcounted.
assert(D->getTypeForDecl()->isTemplateTypeParmType());
Optional<unsigned> NumExpanded;
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 5a2013bd53a7..18864e731f17 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6515,11 +6515,9 @@ QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
ConceptDecl *NewCD = nullptr;
TemplateArgumentListInfo NewTemplateArgs;
NestedNameSpecifierLoc NewNestedNameSpec;
- if (TL.getTypePtr()->isConstrained()) {
- NewCD = cast_or_null<ConceptDecl>(
- getDerived().TransformDecl(
- TL.getConceptNameLoc(),
- TL.getTypePtr()->getTypeConstraintConcept()));
+ if (T->isConstrained()) {
+ NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl(
+ TL.getConceptNameLoc(), T->getTypeConstraintConcept()));
NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
@@ -6541,7 +6539,8 @@ QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
QualType Result = TL.getType();
if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
- T->isDependentType()) {
+ T->isDependentType() || T->isConstrained()) {
+ // FIXME: Maybe don't rebuild if all template arguments are the same.
llvm::SmallVector<TemplateArgument, 4> NewArgList;
NewArgList.reserve(NewArgList.size());
for (const auto &ArgLoc : NewTemplateArgs.arguments())
More information about the cfe-commits
mailing list