diff --git a/clang/include/clang/AST/ASTNodeTraverser.h b/clang/include/clang/AST/ASTNodeTraverser.h --- a/clang/include/clang/AST/ASTNodeTraverser.h +++ b/clang/include/clang/AST/ASTNodeTraverser.h @@ -414,6 +414,10 @@ // FIXME: ElaboratedType, DependentNameType, // DependentTemplateSpecializationType, ObjCObjectType + void VisitTypedefType(const TypedefType *T) { + if (T->hasDifferentUnderlyingType()) + Visit(T->desugar()); + } void VisitTypedefDecl(const TypedefDecl *D) { Visit(D->getUnderlyingType()); } void VisitEnumConstantDecl(const EnumConstantDecl *D) { diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -1734,6 +1734,15 @@ unsigned NumArgs; }; + class TypedefBitfields { + friend class TypedefType; + + unsigned : NumTypeBits; + + /// True if this typedef has underlying type different from decl. + unsigned hasDifferentUnderlyingType : 1; + }; + class SubstTemplateTypeParmPackTypeBitfields { friend class SubstTemplateTypeParmPackType; @@ -1808,6 +1817,7 @@ ConstantArrayTypeBitfields ConstantArrayTypeBits; AttributedTypeBitfields AttributedTypeBits; AutoTypeBitfields AutoTypeBits; + TypedefBitfields TypedefBits; BuiltinTypeBitfields BuiltinTypeBits; FunctionTypeBitfields FunctionTypeBits; ObjCObjectTypeBitfields ObjCObjectTypeBits; @@ -4416,6 +4426,14 @@ public: TypedefNameDecl *getDecl() const { return Decl; } + bool hasDifferentUnderlyingType() const { + return TypedefBits.hasDifferentUnderlyingType; + } + QualType getUnderlyingTypeIfDifferent() { + return hasDifferentUnderlyingType() + ? *reinterpret_cast(this + 1) + : QualType(); + } bool isSugared() const { return true; } QualType desugar() const; @@ -4917,10 +4935,13 @@ // The original type parameter. const TemplateTypeParmType *Replaced; + QualType Replacement; - SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon) - : Type(SubstTemplateTypeParm, Canon, Canon->getDependence()), - Replaced(Param) {} + SubstTemplateTypeParmType(const TemplateTypeParmType *Param, + QualType Replacement) + : Type(SubstTemplateTypeParm, Replacement.getCanonicalType(), + Replacement->getDependence()), + Replaced(Param), Replacement(Replacement) {} public: /// Gets the template parameter that was substituted for. @@ -4930,9 +4951,7 @@ /// Gets the type that was substituted for the template /// parameter. - QualType getReplacementType() const { - return getCanonicalTypeInternal(); - } + QualType getReplacementType() const { return Replacement; } bool isSugared() const { return true; } QualType desugar() const { return getReplacementType(); } diff --git a/clang/include/clang/AST/TypeProperties.td b/clang/include/clang/AST/TypeProperties.td --- a/clang/include/clang/AST/TypeProperties.td +++ b/clang/include/clang/AST/TypeProperties.td @@ -379,16 +379,12 @@ def : Property<"declaration", DeclRef> { let Read = [{ node->getDecl() }]; } - def : Property<"canonicalType", Optional> { - let Read = [{ makeOptionalFromNullable(node->getCanonicalTypeInternal()) }]; + def : Property<"underlyingType", QualType> { + let Read = [{ node->desugar() }]; } def : Creator<[{ - QualType finalCanonicalType = - canonicalType ? ctx.getCanonicalType(*canonicalType) - : QualType(); - return ctx.getTypedefType(cast(declaration), - finalCanonicalType); + return ctx.getTypedefType(cast(declaration), underlyingType); }]>; } diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -465,6 +465,9 @@ /// forward slash (/) elsewhere. bool UseTargetPathSeparator = false; + /// Resugar template specializations. + bool Resugar = true; + LangOptions(); /// Set language defaults for the given input language and diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5743,6 +5743,9 @@ LangOpts<"RecoveryASTType">, DefaultTrue, NegFlag, PosFlag>; +def fno_resugar : Flag<["-"], "fno-resugar">, + HelpText<"Do not resugar template specializations">, + MarshallingInfoNegativeFlag>; let Group = Action_Group in { diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -8626,6 +8626,23 @@ TDK_CUDATargetMismatch }; + TemplateDeductionResult DeduceTemplateArguments( + TemplateParameterList *TemplateParams, ArrayRef Ps, + ArrayRef As, sema::TemplateDeductionInfo &Info, + SmallVectorImpl &Deduced, + bool NumberOfArgumentsMustMatch); + + TemplateDeductionResult + DeduceTemplateArguments(TemplateParameterList *TemplateParams, + const TemplateArgumentList &ParamList, + const TemplateArgumentList &ArgList, + sema::TemplateDeductionInfo &Info, + SmallVectorImpl &Deduced) { + return DeduceTemplateArguments(TemplateParams, ParamList.asArray(), + ArgList.asArray(), Info, Deduced, + /*NumberOfArgumentsMustMatch=*/false); + } + TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, const TemplateArgumentList &TemplateArgs, @@ -9501,6 +9518,8 @@ } }; + QualType resugar(const NestedNameSpecifier *NNS, QualType T); + void PerformPendingInstantiations(bool LocalOnly = false); TypeSourceInfo *SubstType(TypeSourceInfo *T, diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -2358,12 +2358,12 @@ return getTypeInfo(cast(T)->desugar().getTypePtr()); case Type::Typedef: { - const TypedefNameDecl *Typedef = cast(T)->getDecl(); - TypeInfo Info = getTypeInfo(Typedef->getUnderlyingType().getTypePtr()); + const auto *TT = cast(T); + TypeInfo Info = getTypeInfo(TT->desugar().getTypePtr()); // If the typedef has an aligned attribute on it, it overrides any computed // alignment we have. This violates the GCC documentation (which says that // attribute(aligned) can only round up) but matches its implementation. - if (unsigned AttrAlign = Typedef->getMaxAlignment()) { + if (unsigned AttrAlign = TT->getDecl()->getMaxAlignment()) { Align = AttrAlign; AlignRequirement = AlignRequirementKind::RequiredByTypedef; } else { @@ -4618,14 +4618,25 @@ /// specified typedef name decl. QualType ASTContext::getTypedefType(const TypedefNameDecl *Decl, QualType Underlying) const { - if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); - + if (!Decl->TypeForDecl) { + if (Underlying.isNull()) + Underlying = Decl->getUnderlyingType(); + auto *newType = new (*this, TypeAlignment) TypedefType( + Type::Typedef, Decl, QualType(), getCanonicalType(Underlying)); + Decl->TypeForDecl = newType; + Types.push_back(newType); + return QualType(newType, 0); + } if (Underlying.isNull()) - Underlying = Decl->getUnderlyingType(); - QualType Canonical = getCanonicalType(Underlying); - auto *newType = new (*this, TypeAlignment) - TypedefType(Type::Typedef, Decl, Underlying, Canonical); - Decl->TypeForDecl = newType; + return QualType(Decl->TypeForDecl, 0); + assert(hasSameType(Decl->getUnderlyingType(), Underlying)); + if (Decl->getUnderlyingType() == Underlying) + return QualType(Decl->TypeForDecl, 0); + + // FIXME: Unique + void *Mem = Allocate(sizeof(TypedefType) + sizeof(QualType), TypeAlignment); + auto *newType = new (Mem) TypedefType(Type::Typedef, Decl, Underlying, + getCanonicalType(Underlying)); Types.push_back(newType); return QualType(newType, 0); } @@ -4737,9 +4748,6 @@ QualType ASTContext::getSubstTemplateTypeParmType(const TemplateTypeParmType *Parm, QualType Replacement) const { - assert(Replacement.isCanonical() - && "replacement types must always be canonical"); - llvm::FoldingSetNodeID ID; SubstTemplateTypeParmType::Profile(ID, Parm, Replacement); void *InsertPos = nullptr; @@ -7194,8 +7202,7 @@ void ASTContext::setCFConstantStringType(QualType T) { const auto *TD = T->castAs(); CFConstantStringTypeDecl = cast(TD->getDecl()); - const auto *TagType = - CFConstantStringTypeDecl->getUnderlyingType()->castAs(); + const auto *TagType = TD->castAs(); CFConstantStringTagDecl = TagType->getDecl(); } diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -1363,8 +1363,12 @@ Expected ToDeclOrErr = import(T->getDecl()); if (!ToDeclOrErr) return ToDeclOrErr.takeError(); + ExpectedType ToUnderlyingTypeOrErr = import(T->desugar()); + if (!ToUnderlyingTypeOrErr) + return ToUnderlyingTypeOrErr.takeError(); - return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); + return Importer.getToContext().getTypedefType(*ToDeclOrErr, + *ToUnderlyingTypeOrErr); } ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -961,7 +961,9 @@ case Type::Typedef: if (!IsStructurallyEquivalent(Context, cast(T1)->getDecl(), - cast(T2)->getDecl())) + cast(T2)->getDecl()) || + !IsStructurallyEquivalent(Context, cast(T1)->desugar(), + cast(T2)->desugar())) return false; break; diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp --- a/clang/lib/AST/FormatString.cpp +++ b/clang/lib/AST/FormatString.cpp @@ -976,10 +976,10 @@ bool FormatSpecifier::namedTypeToLengthModifier(QualType QT, LengthModifier &LM) { assert(isa(QT) && "Expected a TypedefType"); - const TypedefNameDecl *Typedef = cast(QT)->getDecl(); + const auto *TT = cast(QT); - for (;;) { - const IdentifierInfo *Identifier = Typedef->getIdentifier(); + do { + const IdentifierInfo *Identifier = TT->getDecl()->getIdentifier(); if (Identifier->getName() == "size_t") { LM.setKind(LengthModifier::AsSizeT); return true; @@ -997,12 +997,6 @@ LM.setKind(LengthModifier::AsPtrDiff); return true; } - - QualType T = Typedef->getUnderlyingType(); - if (!isa(T)) - break; - - Typedef = cast(T)->getDecl(); - } + } while (TT = TT->desugar()->getAs()); return false; } diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp --- a/clang/lib/AST/JSONNodeDumper.cpp +++ b/clang/lib/AST/JSONNodeDumper.cpp @@ -530,6 +530,8 @@ void JSONNodeDumper::VisitTypedefType(const TypedefType *TT) { JOS.attribute("decl", createBareDeclRef(TT->getDecl())); + if (TT->hasDifferentUnderlyingType()) + JOS.attribute("type", createQualType(TT->desugar())); } void JSONNodeDumper::VisitFunctionType(const FunctionType *T) { diff --git a/clang/lib/AST/QualTypeNames.cpp b/clang/lib/AST/QualTypeNames.cpp --- a/clang/lib/AST/QualTypeNames.cpp +++ b/clang/lib/AST/QualTypeNames.cpp @@ -253,6 +253,8 @@ true /*FullyQualified*/, WithGlobalNsPrefix); } else if (const auto *TDD = dyn_cast(Type)) { + if (TDD->hasDifferentUnderlyingType()) + return Scope; return TypeName::createNestedNameSpecifier(Ctx, TDD->getDecl(), true /*FullyQualified*/, WithGlobalNsPrefix); @@ -325,7 +327,10 @@ Decl *Decl = nullptr; // There are probably other cases ... if (const auto *TDT = dyn_cast(TypePtr)) { - Decl = TDT->getDecl(); + if (TDT->hasDifferentUnderlyingType()) + Decl = TypePtr->getAsCXXRecordDecl(); + else + Decl = TDT->getDecl(); } else if (const auto *TagDeclType = dyn_cast(TypePtr)) { Decl = TagDeclType->getDecl(); } else if (const auto *TST = dyn_cast(TypePtr)) { diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp --- a/clang/lib/AST/TextNodeDumper.cpp +++ b/clang/lib/AST/TextNodeDumper.cpp @@ -1546,7 +1546,10 @@ } void TextNodeDumper::VisitTypedefType(const TypedefType *T) { - dumpDeclRef(T->getDecl()); + const TypedefNameDecl *D = T->getDecl(); + dumpDeclRef(D); + if (T->hasDifferentUnderlyingType()) + dumpType(T->desugar()); } void TextNodeDumper::VisitUnaryTransformType(const UnaryTransformType *T) { diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -3434,14 +3434,19 @@ } TypedefType::TypedefType(TypeClass tc, const TypedefNameDecl *D, - QualType underlying, QualType can) - : Type(tc, can, toSemanticDependence(underlying->getDependence())), + QualType Underlying, QualType can) + : Type(tc, can, toSemanticDependence(can->getDependence())), Decl(const_cast(D)) { assert(!isa(can) && "Invalid canonical type"); + TypedefBits.hasDifferentUnderlyingType = !Underlying.isNull(); + if (hasDifferentUnderlyingType()) + *reinterpret_cast(this + 1) = Underlying; } QualType TypedefType::desugar() const { - return getDecl()->getUnderlyingType(); + return hasDifferentUnderlyingType() + ? *reinterpret_cast(this + 1) + : Decl->getUnderlyingType(); } UsingType::UsingType(const UsingShadowDecl *Found, QualType Underlying, diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp b/clang/lib/Sema/SemaCXXScopeSpec.cpp --- a/clang/lib/Sema/SemaCXXScopeSpec.cpp +++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp @@ -983,6 +983,7 @@ NoteAllFoundTemplates(Template); return true; } + T = resugar(SS.getScopeRep(), T); // Provide source-location information for the template specialization type. TypeLocBuilder Builder; diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -5676,9 +5676,6 @@ Sema::CCEKind CCE, bool RequireInt, NamedDecl *Dest) { - assert(S.getLangOpts().CPlusPlus11 && - "converted constant expression outside C++11"); - if (checkPlaceholderForOverload(S, From)) return ExprError(); diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -11,6 +11,7 @@ #include "TreeTransform.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/ASTLambda.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclFriend.h" #include "clang/AST/DeclTemplate.h" @@ -90,6 +91,416 @@ return Depth; } +namespace { +class Resugarer : public TreeTransform { + using inherited = TreeTransform; + + MultiLevelTemplateArgumentList *MLTAL = nullptr; + + using DCToArgsMap = + llvm::DenseMap>; + DCToArgsMap *DCToArgs = nullptr; + SmallVector, 4> DeducedArgsBuf; + + struct BuildMLTALRAII { + BuildMLTALRAII(Resugarer &R, const DeclContext *DC, + const ArrayRef *Args = nullptr) + : R(&R), OldMLTAL(std::exchange(R.MLTAL, &MLTAL)) { + if (Args) + MLTAL.addOuterTemplateArguments(*Args); + auto addDC = [&](const DeclContext *DC) { + MLTAL.addOuterTemplateArguments( + R.DCToArgs ? R.DCToArgs->lookup(DC) + : None); // FIXME: add trailing retained outer + }; + while (DC) { + switch (Decl::Kind DK = DC->getDeclKind()) { + case Decl::Kind::ClassTemplatePartialSpecialization: + case Decl::Kind::ClassTemplateSpecialization: { + const auto *CTS = cast(DC); + if (!CTS->isClassScopeExplicitSpecialization()) { + if (CTS->getSpecializationKind() == TSK_ExplicitSpecialization && + DK != Decl::Kind::ClassTemplatePartialSpecialization) + return; + addDC(DC); + assert(CTS->getSpecializedTemplate() && "No class template?"); + if (CTS->getSpecializedTemplate()->isMemberSpecialization()) + return; + break; + } + LLVM_FALLTHROUGH; + } + case Decl::Kind::CXXRecord: { + const auto *RD = cast(DC); + if (const auto *CT = RD->getDescribedClassTemplate()) { + addDC(DC); + if (CT->isMemberSpecialization()) + return; + } + break; + } + case Decl::Kind::CXXConstructor: + case Decl::Kind::CXXDestructor: + case Decl::Kind::CXXConversion: + case Decl::Kind::CXXMethod: + case Decl::Kind::CXXDeductionGuide: + case Decl::Kind::Function: { + const auto *FD = cast(DC); + if (FD->getTemplateSpecializationKindForInstantiation() == + TSK_ExplicitSpecialization) + return; + + if (FD->getTemplateSpecializationKind() == + TSK_ExplicitSpecialization) { + } else if (const TemplateArgumentList *TemplateArgs = + FD->getTemplateSpecializationArgs()) { + addDC(DC); + assert(FD->getPrimaryTemplate() && "No function template?"); + if (FD->getPrimaryTemplate()->isMemberSpecialization() || + isGenericLambdaCallOperatorOrStaticInvokerSpecialization(FD)) + return; + } else if (FD->getDescribedFunctionTemplate()) { + assert(MLTAL.getNumSubstitutedLevels() == 0 && + "Outer template not instantiated?"); + } + if (FD->getFriendObjectKind() && + FD->getDeclContext()->isFileContext()) { + DC = FD->getLexicalDeclContext(); + continue; + } + break; + } + case Decl::Kind::TranslationUnit: + case Decl::Kind::Namespace: + case Decl::Kind::Export: + return; + case Decl::Kind::LinkageSpec: + break; + default: + cast(DC)->dumpColor(); + llvm_unreachable("Unexpected Decl Kind"); + } + DC = DC->getParent(); + } + } + ~BuildMLTALRAII() { R->MLTAL = OldMLTAL; } + + private: + Resugarer *R; + MultiLevelTemplateArgumentList MLTAL, *OldMLTAL; + }; + +public: + struct NamingContextRAII { + NamingContextRAII(Resugarer &R, const NestedNameSpecifier *NNS) + : R(&R), OldDCToArgs(std::exchange(R.DCToArgs, &DCToArgs)), + OldDeducedArgsBufSize(R.DeducedArgsBuf.size()) { + bool InheritOldNamingContext = true; + for (/**/; NNS; NNS = NNS->getPrefix()) { + auto NK = NNS->getKind(); + if (NK == NestedNameSpecifier::Global || + NK == NestedNameSpecifier::Namespace || + NK == NestedNameSpecifier::NamespaceAlias) { + InheritOldNamingContext = false; + break; + } + switch (NK) { + case NestedNameSpecifier::Identifier: + llvm_unreachable(""); + case NestedNameSpecifier::Super: + break; + case NestedNameSpecifier::TypeSpec: + case NestedNameSpecifier::TypeSpecWithTemplate: { + const DeclContext *IDC; + const TemplateSpecializationType *TST; + { + const clang::Type *NT = NNS->getAsType(); + QualType NTCanon = NT->getCanonicalTypeInternal(); + switch (NTCanon->getTypeClass()) { + case Type::Record: { + IDC = NT->getAsRecordDecl(); + TST = NT->getAs(); + while (TST && TST->isTypeAlias()) + TST = + TST->getAliasedType()->getAs(); + break; + } + case Type::InjectedClassName: { + const auto *ICN = cast(NTCanon); + IDC = ICN->getDecl(); + TST = ICN->getInjectedTST(); + break; + } + case Type::TemplateSpecialization: + continue; + default: + NTCanon.dump(); + llvm_unreachable(""); + } + } + switch (auto RDK = IDC->getDeclKind()) { + case Decl::CXXRecord: + continue; + case Decl::ClassTemplateSpecialization: + case Decl::ClassTemplatePartialSpecialization: { + if (!TST) { + DCToArgs.try_emplace(IDC); + continue; + } + assert(!TST->isTypeAlias()); + ArrayRef Args = TST->template_arguments(); + if (RDK == Decl::ClassTemplatePartialSpecialization) { + deduceClassTemplatePartialSpecialization( + cast(IDC), Args, IDC); + continue; + } + if (auto *CTPSD = + cast(IDC) + ->getSpecializedTemplateOrPartial() + .dyn_cast()) + deduceClassTemplatePartialSpecialization(CTPSD, Args, IDC); + else + DCToArgs.try_emplace(IDC, Args); + continue; + } + default: + llvm_unreachable(""); + } + } + default: + llvm_unreachable(""); + } + } + if (InheritOldNamingContext && OldDCToArgs) { + for (auto &&I : *OldDCToArgs) { + auto &R = DCToArgs[I.first]; + if (R.empty()) + R = I.second; + } + } + } + ~NamingContextRAII() { + R->DCToArgs = OldDCToArgs; + R->DeducedArgsBuf.resize(OldDeducedArgsBufSize); + } + + private: + Resugarer *R; + DCToArgsMap DCToArgs, *OldDCToArgs; + size_t OldDeducedArgsBufSize; + + void deduceClassTemplatePartialSpecialization( + const ClassTemplatePartialSpecializationDecl *D, + ArrayRef Args, const DeclContext *DC) { +#if 1 + DCToArgs.try_emplace(DC); +#else + TemplateDeductionInfo Info(SourceLocation{}); + TemplateParameterList *TPL = D->getTemplateParameters(); + SmallVector Deduced(TPL->size()); + Sema::TemplateDeductionResult Res = R->SemaRef.DeduceTemplateArguments( + TPL, D->getTemplateArgs(), + TemplateArgumentList(TemplateArgumentList::OnStackType{}, Args), Info, + Deduced); + if (Res != Sema::TDK_Success) + llvm_unreachable("Unexpected deduction failure"); + DCToArgs.try_emplace( + DC, R->DeducedArgsBuf.emplace_back(Deduced.begin(), Deduced.end())); +#endif + } + }; + + Resugarer(Sema &SemaRef) : inherited(SemaRef) {} + + bool AlwaysRebuild() { return false; } + bool ReplacingOriginal() { return false; } + + QualType TransformElaboratedType(TypeLocBuilder &TLB, ElaboratedTypeLoc TL) { + const ElaboratedType *T = TL.getTypePtr(); + NestedNameSpecifierLoc QualifierLoc; + QualifierLoc = TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); + + NestedNameSpecifier *NNS = QualifierLoc.getNestedNameSpecifier(); + QualType NamedT; + { + NamingContextRAII _(*this, NNS); + NamedT = TransformType(TLB, TL.getNamedTypeLoc()); + } + + QualType Result = + QualifierLoc != TL.getQualifierLoc() || NamedT != T->getNamedType() + ? SemaRef.Context.getElaboratedType(T->getKeyword(), NNS, NamedT) + : TL.getType(); + + ElaboratedTypeLoc NewTL = TLB.push(Result); + NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); + NewTL.setQualifierLoc(QualifierLoc); + return Result; + } + + Decl *TransformDecl(SourceLocation Loc, Decl *D) const { return D; } + + QualType TransformSubstTemplateTypeParmType(TypeLocBuilder &TLB, + SubstTemplateTypeParmTypeLoc TL) { + const SubstTemplateTypeParmType *T = TL.getTypePtr(); + const TemplateTypeParmType *Replaced = T->getReplacedParameter(); + + unsigned Depth = Replaced->getDepth(), Index = Replaced->getIndex(); + if (!MLTAL || !MLTAL->hasTemplateArgument(Depth, Index)) { + auto NewTL = TLB.push(TL.getType()); + NewTL.setNameLoc(TL.getNameLoc()); + return TL.getType(); + } + + QualType Replacement = + (*MLTAL)(Depth, Index).getAsType().getNonPackExpansionType(); + if (!SemaRef.Context.hasSameType(Replacement, T->getReplacementType())) { + Replacement.dump(); + T->getReplacementType().dump(); + assert(false); + } + QualType Result = + SemaRef.Context.getSubstTemplateTypeParmType(Replaced, Replacement); + auto NewTL = TLB.push(Result); + NewTL.setNameLoc(TL.getNameLoc()); + return Result; + } + + using inherited::TransformTemplateSpecializationType; + + QualType TransformTemplateSpecializationType(TypeLocBuilder &TLB, + TemplateSpecializationTypeLoc TL, + TemplateName N) { + const TemplateSpecializationType *T = TL.getTypePtr(); + + TemplateArgumentListInfo NewArgs; + NewArgs.setLAngleLoc(TL.getLAngleLoc()); + NewArgs.setRAngleLoc(TL.getRAngleLoc()); + using Iter = + TemplateArgumentLocContainerIterator; + if (TransformTemplateArguments(Iter(TL, 0), Iter(TL, TL.getNumArgs()), + NewArgs)) + llvm_unreachable(""); + + TemplateDecl *TD = N.getAsTemplateDecl(); + QualType Result; + if (T->isTypeAlias()) { + QualType Underlying; + { + SmallVector Args(NewArgs.size()); + for (int I = 0; I < Args.size(); ++I) + Args[I] = NewArgs[I].getArgument(); + ArrayRef RArgs(Args); + BuildMLTALRAII _(*this, TD->getDeclContext(), &RArgs); + Underlying = TransformType(T->getAliasedType()); + } + Result = + SemaRef.Context.getTemplateSpecializationType(N, NewArgs, Underlying); + } else { + Result = SemaRef.Context.getTemplateSpecializationType(N, NewArgs, + TL.getType()); + } + TemplateSpecializationTypeLoc NewTL = + TLB.push(Result); + NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); + NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); + NewTL.setLAngleLoc(TL.getLAngleLoc()); + NewTL.setRAngleLoc(TL.getRAngleLoc()); + for (unsigned i = 0, e = NewArgs.size(); i != e; ++i) + NewTL.setArgLocInfo(i, NewArgs[i].getLocInfo()); + return Result; + } + + bool TransformTemplateArgument(const TemplateArgumentLoc &Input, + TemplateArgumentLoc &Output, bool Uneval) { + const TemplateArgument &Arg = Input.getArgument(); + if (Arg.getKind() != TemplateArgument::Expression) + return inherited::TransformTemplateArgument(Input, Output, Uneval); + + Expr *InputExpr = Input.getSourceExpression(); + if (!InputExpr) + InputExpr = Arg.getAsExpr(); + ExprResult E = getDerived().TransformExpr(InputExpr); + Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get()); + return false; + } + + StmtResult TransformReturnStmt(ReturnStmt *S) { llvm_unreachable(""); } + + ExprResult TransformLambdaExpr(LambdaExpr *E) { + llvm::SmallVector CaptureInits(E->capture_size()); + bool AnyDifferentCaptureInit = false; + llvm::transform(E->capture_inits(), CaptureInits.begin(), [&](Expr *E) { + ExprResult ER = TransformExpr(E); + assert(!ER.isInvalid()); + if (E != ER.get()) + AnyDifferentCaptureInit = true; + return ER.get(); + }); + if (!AnyDifferentCaptureInit) + return E; + return LambdaExpr::Create( + SemaRef.Context, E->getLambdaClass(), E->getIntroducerRange(), + E->getCaptureDefault(), E->getCaptureDefaultLoc(), + E->hasExplicitParameters(), E->hasExplicitResultType(), CaptureInits, + E->getEndLoc(), E->containsUnexpandedParameterPack()); + } + + TemplateName TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, + SourceLocation NameLoc, + QualType ObjectType = QualType(), + NamedDecl *FirstQualifierInScope = nullptr, + bool AllowInjectedClassName = false) { + if (Name.getKind() == TemplateName::NameKind::SubstTemplateTemplateParm) + return Name; + return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType, + FirstQualifierInScope, + AllowInjectedClassName); + } + + QualType TransformDependentNameType(TypeLocBuilder &TLB, + DependentNameTypeLoc TL, + bool DeducedTSTContext = false) { + const DependentNameType *T = TL.getTypePtr(); + + NestedNameSpecifierLoc QualifierLoc = + TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); + assert(QualifierLoc); + assert(QualifierLoc.getNestedNameSpecifier()->isDependent()); + QualType Result = SemaRef.Context.getDependentNameType( + T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), + T->getIdentifier()); + DependentNameTypeLoc NewTL = TLB.push(Result); + NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); + NewTL.setQualifierLoc(QualifierLoc); + NewTL.setNameLoc(TL.getNameLoc()); + return Result; + } + + QualType TransformTypedefType(TypeLocBuilder &TLB, TypedefTypeLoc TL) { + const TypedefType *T = TL.getTypePtr(); + const TypedefNameDecl *D = T->getDecl(); + QualType Underlying = D->getUnderlyingType(); + BuildMLTALRAII DCScope(*this, D->getDeclContext()); + QualType NewUnderlying = TransformType(D->getUnderlyingType()); + QualType Result = TL.getType(); + if (NewUnderlying != Underlying) + Result = SemaRef.Context.getTypedefType(D, NewUnderlying); + TypedefTypeLoc NewTL = TLB.push(Result); + NewTL.setNameLoc(TL.getNameLoc()); + return Result; + } +}; +} // namespace + +QualType Sema::resugar(const NestedNameSpecifier *NNS, QualType T) { + if (!getLangOpts().Resugar) + return T; + Resugarer R(*this); + Resugarer::NamingContextRAII NamingScope(R, NNS); + return R.TransformType(T); +} + /// \brief Determine whether the declaration found is acceptable as the name /// of a template and, if so, return that template declaration. Otherwise, /// returns null. @@ -3981,9 +4392,10 @@ return CreateParsedType(T, TLB.getTypeSourceInfo(Context, T)); } - QualType Result = CheckTemplateIdType(Template, TemplateIILoc, TemplateArgs); - if (Result.isNull()) + QualType T = CheckTemplateIdType(Template, TemplateIILoc, TemplateArgs); + if (T.isNull()) return true; + QualType Result = resugar(SS.getScopeRep(), T); // Build type-source information. TypeLocBuilder TLB; @@ -4066,9 +4478,10 @@ Diag(TAT->getLocation(), diag::note_declared_at); } - QualType Result = CheckTemplateIdType(Template, TemplateLoc, TemplateArgs); - if (Result.isNull()) + QualType T = CheckTemplateIdType(Template, TemplateLoc, TemplateArgs); + if (T.isNull()) return TypeResult(true); + QualType Result = resugar(SS.getScopeRep(), T); // Check the tag kind if (const RecordType *RT = Result->getAs()) { @@ -10401,6 +10814,7 @@ /*DeducedTSTContext=*/true); if (T.isNull()) return true; + // T.dump(); return CreateParsedType(T, TSI); } @@ -10467,6 +10881,7 @@ QualType T = CheckTemplateIdType(Template, TemplateIILoc, TemplateArgs); if (T.isNull()) return true; + T = resugar(SS.getScopeRep(), T); // Provide source-location information for the template specialization type. TypeLocBuilder Builder; @@ -10691,9 +11106,10 @@ // We found a type. Build an ElaboratedType, since the // typename-specifier was just sugar. MarkAnyDeclReferenced(Type->getLocation(), Type, /*OdrUse=*/false); - return Context.getElaboratedType(Keyword, - QualifierLoc.getNestedNameSpecifier(), - Context.getTypeDeclType(Type)); + QualType T = Context.getTypeDeclType(Type); + NestedNameSpecifier *NNS = QualifierLoc.getNestedNameSpecifier(); + QualType ResugaredT = resugar(NNS, T); + return Context.getElaboratedType(Keyword, NNS, ResugaredT); } // C++ [dcl.type.simple]p2: diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -137,14 +137,6 @@ SmallVectorImpl &Deduced, unsigned TDF, bool PartialOrdering = false, bool DeducedFromArrayBound = false); -static Sema::TemplateDeductionResult -DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams, - ArrayRef Ps, - ArrayRef As, - TemplateDeductionInfo &Info, - SmallVectorImpl &Deduced, - bool NumberOfArgumentsMustMatch); - static void MarkUsedTemplateParameters(ASTContext &Ctx, const TemplateArgument &TemplateArg, bool OnlyDeduced, unsigned Depth, @@ -574,9 +566,9 @@ // Perform template argument deduction on each template // argument. Ignore any missing/extra arguments, since they could be // filled in by default arguments. - return DeduceTemplateArguments(S, TemplateParams, PResolved, - SA->template_arguments(), Info, Deduced, - /*NumberOfArgumentsMustMatch=*/false); + return S.DeduceTemplateArguments(TemplateParams, TP->template_arguments(), + SA->template_arguments(), Info, Deduced, + /*NumberOfArgumentsMustMatch=*/false); } // If the argument type is a class template specialization, we @@ -598,9 +590,9 @@ return Result; // Perform template argument deduction for the template arguments. - return DeduceTemplateArguments(S, TemplateParams, PResolved, - SA->getTemplateArgs().asArray(), Info, Deduced, - /*NumberOfArgumentsMustMatch=*/true); + return S.DeduceTemplateArguments( + TemplateParams, PResolved, SA->getTemplateArgs().asArray(), Info, Deduced, + /*NumberOfArgumentsMustMatch=*/true); } static bool IsPossiblyOpaquelyQualifiedTypeInternal(const Type *T) { @@ -2243,9 +2235,51 @@ return Sema::TDK_NonDeducedMismatch; case TemplateArgument::Integral: - if (A.getKind() == TemplateArgument::Integral) { + switch (A.getKind()) { + case TemplateArgument::Integral: if (hasSameExtendedValue(P.getAsIntegral(), A.getAsIntegral())) return Sema::TDK_Success; + break; + case TemplateArgument::Expression: { + TemplateArgument Resolved; + Expr *AE = A.getAsExpr(); + QualType AT = AE->getType(); + // FIXME: Copypasta from CheckTemplateArgument + + APValue Value; + if (auto *CE = dyn_cast(AE)) { + Value = CE->getAPValueResult(); + } else { + ExprResult ArgResult = S.CheckConvertedConstantExpression( + AE, AT, Value, Sema::CCEK_TemplateArg); + if (ArgResult.isInvalid()) + break; + + // For a value-dependent argument, CheckConvertedConstantExpression is + // permitted (and expected) to be unable to determine a value. + if (ArgResult.get()->isValueDependent()) + break; + } + // Convert the APValue to a TemplateArgument. + switch (Value.getKind()) { + case APValue::None: + assert(AT->isNullPtrType()); + Resolved = TemplateArgument(AT, /*isNullPtr*/ true); + break; + case APValue::Indeterminate: + llvm_unreachable("result of constant evaluation should be initialized"); + case APValue::Int: + assert(AT->isIntegralOrEnumerationType()); + Resolved = TemplateArgument(S.Context, Value.getInt(), AT); + break; + default: + llvm_unreachable("unhandled"); + } + return DeduceTemplateArguments(S, TemplateParams, P, Resolved, Info, + Deduced); + } + default: + break; } Info.FirstArg = P; Info.SecondArg = A; @@ -2326,13 +2360,11 @@ return false; } -static Sema::TemplateDeductionResult -DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams, - ArrayRef Ps, - ArrayRef As, - TemplateDeductionInfo &Info, - SmallVectorImpl &Deduced, - bool NumberOfArgumentsMustMatch) { +Sema::TemplateDeductionResult Sema::DeduceTemplateArguments( + TemplateParameterList *TemplateParams, ArrayRef Ps, + ArrayRef As, TemplateDeductionInfo &Info, + SmallVectorImpl &Deduced, + bool NumberOfArgumentsMustMatch) { // C++0x [temp.deduct.type]p9: // If the template argument list of P contains a pack expansion that is not // the last template argument, the entire template argument list is a @@ -2363,8 +2395,8 @@ return Sema::TDK_MiscellaneousDeductionFailure; // Perform deduction for this Pi/Ai pair. - if (auto Result = DeduceTemplateArguments(S, TemplateParams, P, - As[ArgIdx], Info, Deduced)) + if (auto Result = ::DeduceTemplateArguments(*this, TemplateParams, P, + As[ArgIdx], Info, Deduced)) return Result; // Move to the next argument. @@ -2382,7 +2414,7 @@ TemplateArgument Pattern = P.getPackExpansionPattern(); // Prepare to deduce the packs within the pattern. - PackDeductionScope PackScope(S, TemplateParams, Deduced, Info, Pattern); + PackDeductionScope PackScope(*this, TemplateParams, Deduced, Info, Pattern); // Keep track of the deduced template arguments for each parameter pack // expanded by this pack expansion (the outer index) and for each @@ -2391,8 +2423,8 @@ PackScope.hasNextElement(); ++ArgIdx) { // Deduce template arguments from the pattern. - if (auto Result = DeduceTemplateArguments(S, TemplateParams, Pattern, - As[ArgIdx], Info, Deduced)) + if (auto Result = ::DeduceTemplateArguments( + *this, TemplateParams, Pattern, As[ArgIdx], Info, Deduced)) return Result; PackScope.nextPackElement(); @@ -2407,17 +2439,6 @@ return Sema::TDK_Success; } -static Sema::TemplateDeductionResult -DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams, - const TemplateArgumentList &ParamList, - const TemplateArgumentList &ArgList, - TemplateDeductionInfo &Info, - SmallVectorImpl &Deduced) { - return DeduceTemplateArguments(S, TemplateParams, ParamList.asArray(), - ArgList.asArray(), Info, Deduced, - /*NumberOfArgumentsMustMatch=*/false); -} - /// Determine whether two template arguments are the same. static bool isSameTemplateArg(ASTContext &Context, TemplateArgument X, @@ -2960,11 +2981,9 @@ SmallVector Deduced; Deduced.resize(Partial->getTemplateParameters()->size()); - if (TemplateDeductionResult Result - = ::DeduceTemplateArguments(*this, - Partial->getTemplateParameters(), - Partial->getTemplateArgs(), - TemplateArgs, Info, Deduced)) + if (TemplateDeductionResult Result = DeduceTemplateArguments( + Partial->getTemplateParameters(), Partial->getTemplateArgs(), + TemplateArgs, Info, Deduced)) return Result; SmallVector DeducedArgs(Deduced.begin(), Deduced.end()); @@ -3012,8 +3031,8 @@ SmallVector Deduced; Deduced.resize(Partial->getTemplateParameters()->size()); - if (TemplateDeductionResult Result = ::DeduceTemplateArguments( - *this, Partial->getTemplateParameters(), Partial->getTemplateArgs(), + if (TemplateDeductionResult Result = DeduceTemplateArguments( + Partial->getTemplateParameters(), Partial->getTemplateArgs(), TemplateArgs, Info, Deduced)) return Result; diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -1839,9 +1839,18 @@ QualType Replacement = Arg.getAsType(); - // TODO: only do this uniquing once, at the start of instantiation. - QualType Result - = getSema().Context.getSubstTemplateTypeParmType(T, Replacement); + QualType Result; + if (T->isParameterPack()) { + QualType NewT = getSema().Context.getTemplateTypeParmType( + T->getDepth(), + T->getIndex() + getSema().ArgumentPackSubstitutionIndex, false); + Result = getSema().Context.getSubstTemplateTypeParmType( + cast(NewT), Replacement); + } else { + // TODO: only do this uniquing once, at the start of instantiation. + Result = getSema().Context.getSubstTemplateTypeParmType(T, Replacement); + } + SubstTemplateTypeParmTypeLoc NewTL = TLB.push(Result); NewTL.setNameLoc(TL.getNameLoc()); diff --git a/clang/test/CXX/temp/temp.deduct.guide/p3.cpp b/clang/test/CXX/temp/temp.deduct.guide/p3.cpp --- a/clang/test/CXX/temp/temp.deduct.guide/p3.cpp +++ b/clang/test/CXX/temp/temp.deduct.guide/p3.cpp @@ -33,7 +33,7 @@ }; A(int) -> int; // expected-error {{deduced type 'int' of deduction guide is not a specialization of template 'A'}} -template A(T) -> B; // expected-error {{deduced type 'B' (aka 'A') of deduction guide is not written as a specialization of template 'A'}} +template A(T)->B; // expected-error {{deduced type 'B' (aka 'A') of deduction guide is not written as a specialization of template 'A'}} template A(T*) -> const A; // expected-error {{deduced type 'const A' of deduction guide is not a specialization of template 'A'}} // A deduction-guide shall be declared in the same scope as the corresponding diff --git a/clang/test/CodeGenCXX/mangle-ms-back-references-pr13207.cpp b/clang/test/CodeGenCXX/mangle-ms-back-references-pr13207.cpp --- a/clang/test/CodeGenCXX/mangle-ms-back-references-pr13207.cpp +++ b/clang/test/CodeGenCXX/mangle-ms-back-references-pr13207.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-win32 | FileCheck %s +// RUN: %clang_cc1 -fno-resugar -emit-llvm %s -o - -triple=i386-pc-win32 | FileCheck %s template class A {}; @@ -220,6 +220,7 @@ class T20> struct Food {}; +// FIXME: Should implement resugaring cache for this. using B0 = Food; using B1 = Food; using B2 = Food; diff --git a/clang/test/CodeGenCXX/pr29160.cpp b/clang/test/CodeGenCXX/pr29160.cpp --- a/clang/test/CodeGenCXX/pr29160.cpp +++ b/clang/test/CodeGenCXX/pr29160.cpp @@ -1,8 +1,9 @@ -// RUN: %clang_cc1 -std=c++11 -triple i686-linux-gnu %s -o /dev/null -S -emit-llvm +// RUN: %clang_cc1 -std=c++11 -fno-resugar -triple i686-linux-gnu %s -o /dev/null -S -emit-llvm // // This test's failure mode is running ~forever. (For some value of "forever" // that's greater than 25 minutes on my machine) +// FIXME: Should implement resugaring cache for this. template struct Foo { template diff --git a/clang/test/Misc/diag-template-diffing.cpp b/clang/test/Misc/diag-template-diffing.cpp --- a/clang/test/Misc/diag-template-diffing.cpp +++ b/clang/test/Misc/diag-template-diffing.cpp @@ -257,24 +257,21 @@ int k9 = f9(V9()); // CHECK-ELIDE-NOTREE: no matching function for call to 'f9' -// CHECK-ELIDE-NOTREE: candidate function not viable: no known conversion from 'S9<[2 * ...], S9<[2 * ...], double>>' to 'S9<[2 * ...], S9<[2 * ...], const double>>' for 1st argument +// CHECK-ELIDE-NOTREE: candidate function not viable: no known conversion from 'S9<[2 * ...], U9>' to 'S9<[2 * ...], U9>' for 1st argument // CHECK-NOELIDE-NOTREE: no matching function for call to 'f9' -// CHECK-NOELIDE-NOTREE: candidate function not viable: no known conversion from 'S9>' to 'S9>' for 1st argument +// CHECK-NOELIDE-NOTREE: candidate function not viable: no known conversion from 'S9>' to 'S9>' for 1st argument // CHECK-ELIDE-TREE: no matching function for call to 'f9' // CHECK-ELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument // CHECK-ELIDE-TREE: S9< -// CHECK-ELIDE-TREE: [2 * ...], -// CHECK-ELIDE-TREE: S9< -// CHECK-ELIDE-TREE: [2 * ...], +// CHECK-ELIDE-TREE: [2 * ...], +// CHECK-ELIDE-TREE: U9< // CHECK-ELIDE-TREE: [double != const double]>> // CHECK-NOELIDE-TREE: no matching function for call to 'f9' // CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument // CHECK-NOELIDE-TREE: S9< -// CHECK-NOELIDE-TREE: int, -// CHECK-NOELIDE-TREE: char, -// CHECK-NOELIDE-TREE: S9< -// CHECK-NOELIDE-TREE: int, -// CHECK-NOELIDE-TREE: char, +// CHECK-NOELIDE-TREE: int, +// CHECK-NOELIDE-TREE: char, +// CHECK-NOELIDE-TREE: U9< // CHECK-NOELIDE-TREE: [double != const double]>> template class class_types {}; diff --git a/clang/test/Sema/resugar.cpp b/clang/test/Sema/resugar.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Sema/resugar.cpp @@ -0,0 +1,154 @@ +// RUN: %clang_cc1 -std=c++2b -verify %s +// expected-no-diagnostics + +static constexpr int alignment = 64; // Suitable large alignment. + +struct Baz {}; +using Bar [[gnu::aligned(alignment)]] = Baz; + +#define TEST(X) static_assert(alignof(X) == alignment) +#define TEST_NOT(X) static_assert(alignof(X) != alignment) + +// Sanity checks. +TEST_NOT(Baz); +TEST(Bar); + +namespace t1 { +template struct foo { using type = T; }; +template struct foo { using type = U; }; + +TEST(typename foo::type); +TEST_NOT(typename foo::type); // FIXME +} // namespace t1 + +namespace t2 { +template struct foo1 { using type = T; }; +template struct foo2 { using type = typename foo1<1, T>::type; }; +TEST(typename foo2::type); +} // namespace t2 + +namespace t3 { +template struct foo1 { + template struct foo2 { using type1 = T; }; + using type2 = typename foo2<1, int>::type1; +}; +TEST(typename foo1::type2); +} // namespace t3 + +namespace t4 { +template struct foo { + template using type1 = T; + using type2 = type1; +}; +TEST(typename foo::type2); +} // namespace t4 + +namespace t5 { +template struct foo { + template using type1 = U; + using type2 = type1<1, T>; +}; +TEST(typename foo::type2); +} // namespace t5 + +namespace t6 { +template struct foo1 { + template struct foo2 { using type = U; }; + using type2 = typename foo2<1, T>::type; +}; +TEST(typename foo1::type2); +}; // namespace t6 + +namespace t7 { +template struct foo { + template using type1 = U; +}; +using type2 = typename foo::template type1<1, Bar>; +TEST(type2); +} // namespace t7 + +namespace t8 { +template struct foo { + using type1 = T; +}; +template using type2 = T; +using type3 = typename type2, int>::type1; +TEST(type3); +} // namespace t8 + +namespace t9 { +template struct Y { + using type1 = A; + using type2 = B; +}; +template using Z = Y; +template struct foo { + template using apply = Z; +}; +using T1 = foo::apply; +TEST_NOT(T1::type1); +TEST_NOT(T1::type2); // FIXME + +using T2 = foo::apply; +TEST_NOT(T2::type1); +TEST_NOT(T2::type2); // FIXME +} // namespace t9 + +namespace t10 { +template struct Y { + using type1 = A1; + using type2 = A2; +}; +template using Z = Y; +template struct foo { + template using bind = Z; +}; +using T1 = foo::bind; +TEST_NOT(T1::type1); +TEST_NOT(T1::type2); // FIXME + +using T2 = foo::bind; +TEST_NOT(T2::type1); +TEST_NOT(T2::type2); // FIXME +} // namespace t10 + +namespace t11 { +template