[clang] [clang-tools-extra] [Clang] support friend declarations with a dependent nested-name-specifier (PR #191268)
Yanzuo Liu via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 10 21:59:46 PDT 2026
================
@@ -18629,18 +18669,24 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, Declarator &D,
Diag(FD->getLocation(), diag::err_friend_decl_with_def_arg_must_be_def);
}
- // Mark templated-scope function declarations as unsupported.
- if (!FD->getTemplateParameterLists().empty() && SS.isValid()) {
- Diag(FD->getLocation(), diag::warn_template_qualified_friend_unsupported)
- << SS.getScopeRep() << SS.getRange()
- << cast<CXXRecordDecl>(CurContext);
- FrD->setUnsupportedFriend(true);
+ ArrayRef<TemplateParameterList *> TPL = FD->getTemplateParameterLists();
+ FriendDecl *Friend;
+ if (TPL.size() > 0 && SS.isValid()) {
+ if (CheckTemplateDeclScope(S, TPL.back()))
+ return nullptr;
+
+ Friend =
+ FriendTemplateDecl::Create(Context, CurContext, D.getIdentifierLoc(),
+ ND, DS.getFriendSpecLoc(), TPL);
+ } else {
+ Friend = FriendDecl::Create(Context, CurContext, D.getIdentifierLoc(), ND,
+ DS.getFriendSpecLoc());
}
- }
- warnOnReservedIdentifier(ND);
+ Friend->setAccess(AS_public);
+ CurContext->addDecl(Friend);
- return ND;
+ return ND;
----------------
zwuis wrote:
Wrong indentation.
https://github.com/llvm/llvm-project/pull/191268
More information about the cfe-commits
mailing list