[clang] [clang][ASTImporter] Allow import of similar friend template with different depth (PR #115734)

Balázs Kéri via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 12 02:06:19 PST 2024


================
@@ -6120,6 +6119,19 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
           // see ASTTests test ImportExistingFriendClassTemplateDef.
           continue;
         }
+        // When importing a friend, it is possible that multiple declarations
+        // with same name can co-exist in specific cases (if a template contains
+        // a friend template and has a specialization). For this case the
+        // declarations should match, except that the "template depth" is
+        // different. No linking of previous declaration is needed in this case.
+        // FIXME: This condition may need refinement.
+        if (D->getFriendObjectKind() != Decl::FOK_None &&
+            FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
+            D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
+            IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
+                              /*IgnoreTemplateParmDepth=*/true))
+          continue;
----------------
balazske wrote:

I did not want to modify an already working code part when it is not obvious that the change has no effect on the old behavior. In the new case we already know that there is no structural match and depth was not ignored, then we can check if these match with ignored depth (and this second structural equivalence check looks required to not import non-matching friends). We do not need any of the actions in the `if` branch at line 6108, only a `continue` (and it is not "dependent friend").

https://github.com/llvm/llvm-project/pull/115734


More information about the cfe-commits mailing list