[clang] [Clang][Sema] fix a bug on constraint check with template friend function (PR #90646)

Qizhi Hu via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 30 15:48:05 PDT 2024


jcsxky wrote:

> I'm actually working on constraint checking for function template specializations in #88963. I don't think this patch is quite right... this will cause a crash if the befriended function is a member of a class template specialization. Relative to the changes in #88963, I believe the correct fix would be to change line 278 to:
> 
> ```c++
> if (RelativeToPrimary &&
>     (Function->getTemplateSpecializationKind() ==
>          TSK_ExplicitSpecialization ||
>      (Function->getFriendObjectKind() &&
>       !Function->getPrimaryTemplate()->getFriendObjectKind())))
>   return Response::UseNextDecl(Function);
> ```
> 
> I added a commit to #88963 which makes this change ([be79079](https://github.com/llvm/llvm-project/commit/be79079507ffbd9b29683498f405dc2c32dd8ba7))
> 
> cc @erichkeane

Only when the friend function doesn't use any other new template parameters, i.e. their depth is equal can we skip to add the outer arguments to `MTAL`.

> this will cause a crash if the befriended function is a member of a class template specialization

Could you please provide a testcase?

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


More information about the cfe-commits mailing list