================
@@ -4725,12 +4725,62 @@ Decl 
*TemplateDeclInstantiator::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D)
 }
 
 Decl *TemplateDeclInstantiator::VisitFriendTemplateDecl(FriendTemplateDecl *D) 
{
-  // FIXME: We need to be able to instantiate FriendTemplateDecls.
-  unsigned DiagID = SemaRef.getDiagnostics().getCustomDiagID(
-                                               DiagnosticsEngine::Error,
-                                               "cannot instantiate %0 yet");
-  SemaRef.Diag(D->getLocation(), DiagID)
-    << D->getDeclKindName();
+  ArrayRef<TemplateParameterList *> TPLists =
+      D->getFriendTypeTemplateParameterLists();
+
+  Decl *FTD = nullptr;
+  if (TypeSourceInfo *FT = D->getFriendType()) {
+    if (D->isPackExpansion() && InstantiateFriendPackExpansion(D, FT, TPLists))
+      return nullptr;
+
+    SmallVector<TemplateParameterList *, 1> TPL;
+    if (SubstTemplateParameterLists(TPLists, TPL))
+      return nullptr;
+
+    ClassTemplateDecl *CTD = nullptr;
+    if (auto DNT = FT->getTypeLoc().getAs<DependentNameTypeLoc>()) {
+      NestedNameSpecifierLoc QualifierLoc = 
SemaRef.SubstNestedNameSpecifierLoc(
+          DNT.getQualifierLoc(), TemplateArgs);
+      if (QualifierLoc) {
+        CXXScopeSpec SS;
+        SS.Adopt(QualifierLoc);
+
+        DeclContext *DC =
+            SemaRef.computeDeclContext(SS, /*EnteringContext=*/true);
+        if (DC) {
+          LookupResult Result(SemaRef, DNT.getTypePtr()->getIdentifier(),
+                              DNT.getNameLoc(), Sema::LookupOrdinaryName,
+                              SemaRef.forRedeclarationInCurContext());
+          SemaRef.LookupQualifiedName(Result, DC);
+          CTD = Result.getAsSingle<ClassTemplateDecl>();
----------------
mizvekov wrote:

There is a lot that could be going on here, that this seemingly doesn't handle.

For example, what if the class is found through a UsingDecl?

Also, shouldn't the FriendTemplate also store the Qualifier?

It would e useful if the FriendTemplateDecl could preserve that.

A TemplateName can represent all of that, maybe the FriendTemplateDecl should 
just use that instead of the TemplateDecl directly?

https://github.com/llvm/llvm-project/pull/191268
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to