[PATCH] D156693: [clang][ASTImporter]Skip check friend template declaration in VisitClassTemplateDecl

Qizhi Hu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 5 09:36:13 PDT 2023


jcsxky added a comment.

In D156693#4560110 <https://reviews.llvm.org/D156693#4560110>, @balazske wrote:

> The summary tells nothing about what is the real problem to fix here. In the lit test I see that an error message is displayed, this causes the test failure. The problem is that the structural equivalence check is not good for this special case. The imported AST contains a class template specialization for `A`, in this specialization the friend class template `A` has a previous decl that points to the original friend class template that is in a `ClassTemplateDecl`. In the specialization the "depth" of template arguments is 0, but in the original template it is 1 (the "to" code at import contains only the "original template", no specialization). This difference in the "depth" causes the type mismatch when the specialization is imported.
> AST dump of this code can show the problem:
>
>   template<class T, T U>
>   class A;
>   
>   template<class T, T U>
>   class A {
>   public:
>     template<class P, P Q>
>     friend class A;
>   
>     A(T x):x(x){}
>   	
>   private:
>     T x;
>   };
>   
>   A<int,3> a1(0);
>
> It is really interesting that at friend templates the depth is 1 but friend declarations point to objects outside the class, so really the depth should not increase in a friend template from this point of view. But this is an AST issue.

Depth of specialization friend template is 0 while it is 1 in class declaration  is reasonable, because after template class specialization there not exists template parameter and the friend template becomes outermost scope, thus depth is 0. Thanks to the different of depth causes the non equivalence of the two 'NonTypeTemplateParm', I think there should ignore comparing the depth in this special case to make two types equivalence.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156693/new/

https://reviews.llvm.org/D156693



More information about the cfe-commits mailing list