diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index 59549dbfba2bb..748a48f8eca4b 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 a4cbb2e8e9d57..cfafd423fa5fb 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(TC->getImmediatelyDeclaredConstraint()) - ->getEllipsisLoc() + ->getEllipsisLoc() : SourceLocation())) return nullptr; } diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 1d572054e5fb7..cbd29701496b5 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 NumExpanded; diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 5a2013bd53a7a..18864e731f17f 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -6515,11 +6515,9 @@ QualType TreeTransform::TransformAutoType(TypeLocBuilder &TLB, ConceptDecl *NewCD = nullptr; TemplateArgumentListInfo NewTemplateArgs; NestedNameSpecifierLoc NewNestedNameSpec; - if (TL.getTypePtr()->isConstrained()) { - NewCD = cast_or_null( - getDerived().TransformDecl( - TL.getConceptNameLoc(), - TL.getTypePtr()->getTypeConstraintConcept())); + if (T->isConstrained()) { + NewCD = cast_or_null(getDerived().TransformDecl( + TL.getConceptNameLoc(), T->getTypeConstraintConcept())); NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); @@ -6541,7 +6539,8 @@ QualType TreeTransform::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 NewArgList; NewArgList.reserve(NewArgList.size()); for (const auto &ArgLoc : NewTemplateArgs.arguments())