Closing https://github.com/llvm/llvm-project/issues/56826.
The root cause for pr56826 is: when we collect the template args for the friend, we need to judge if the friend lives in file context. However, if the friend lives in ExportDecl lexically, the judgement here is invalid.
The solution is easy. We should judge the non transparent context and the ExportDecl is transparent context. So the solution should be good.
A main concern may be the patch doesn't handle all the places of the same defect. I think it might not be bad since the patch itself should be innocent.
Another alternative may let the Decl::getContext() return non transparent context but I feel it changes too drastically.
Export declaration has already been the transparent declaration for a long time. But we just forget to edit the comment.