================
@@ -18561,81 +18604,84 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S,
Declarator &D,
PushOnScopeChains(ND, EnclosingScope, /*AddToContext=*/ false);
}
- FriendDecl *FrD = FriendDecl::Create(Context, CurContext,
- D.getIdentifierLoc(), ND,
- DS.getFriendSpecLoc());
- FrD->setAccess(AS_public);
- CurContext->addDecl(FrD);
+ warnOnReservedIdentifier(ND);
- if (ND->isInvalidDecl()) {
- FrD->setInvalidDecl();
- } else {
- if (DC->isRecord()) CheckFriendAccess(ND);
+ if (ND->isInvalidDecl())
+ return ND;
- FunctionDecl *FD;
- if (FunctionTemplateDecl *FTD = dyn_cast<FunctionTemplateDecl>(ND))
- FD = FTD->getTemplatedDecl();
- else
- FD = cast<FunctionDecl>(ND);
-
- // C++ [class.friend]p6:
- // A function may be defined in a friend declaration of a class if and
- // only if the class is a non-local class, and the function name is
- // unqualified.
- if (D.isFunctionDefinition()) {
- // Qualified friend function definition.
- if (SS.isNotEmpty()) {
- // FIXME: We should only do this if the scope specifier names the
- // innermost enclosing namespace; otherwise the fixit changes the
- // meaning of the code.
- SemaDiagnosticBuilder DB =
- Diag(SS.getRange().getBegin(), diag::err_qualified_friend_def);
-
- DB << SS.getScopeRep();
- if (DC->isFileContext())
- DB << FixItHint::CreateRemoval(SS.getRange());
-
- // Friend function defined in a local class.
- } else if (FunctionContainingLocalClass) {
- Diag(NameInfo.getBeginLoc(), diag::err_friend_def_in_local_class);
-
- // Per [basic.pre]p4, a template-id is not a name. Therefore, if we
have
- // a template-id, the function name is not unqualified because these is
- // no name. While the wording requires some reading in-between the
- // lines, GCC, MSVC, and EDG all consider a friend function
- // specialization definitions to be de facto explicit specialization
- // and diagnose them as such.
- } else if (isTemplateId) {
- Diag(NameInfo.getBeginLoc(), diag::err_friend_specialization_def);
- }
- }
+ if (DC->isRecord())
+ CheckFriendAccess(ND);
- // C++11 [dcl.fct.default]p4: If a friend declaration specifies a
- // default argument expression, that declaration shall be a definition
- // and shall be the only declaration of the function or function
- // template in the translation unit.
- if (functionDeclHasDefaultArgument(FD)) {
- // We can't look at FD->getPreviousDecl() because it may not have been
set
- // if we're in a dependent context. If the function is known to be a
- // redeclaration, we will have narrowed Previous down to the right decl.
- if (D.isRedeclaration()) {
- Diag(FD->getLocation(), diag::err_friend_decl_with_def_arg_redeclared);
- Diag(Previous.getRepresentativeDecl()->getLocation(),
- diag::note_previous_declaration);
- } else if (!D.isFunctionDefinition())
- Diag(FD->getLocation(),
diag::err_friend_decl_with_def_arg_must_be_def);
- }
+ FunctionDecl *FD;
+ if (FunctionTemplateDecl *FTD = dyn_cast<FunctionTemplateDecl>(ND))
+ FD = FTD->getTemplatedDecl();
+ else
+ FD = cast<FunctionDecl>(ND);
+
+ // C++ [class.friend]p6:
+ // A function may be defined in a friend declaration of a class if and
+ // only if the class is a non-local class, and the function name is
+ // unqualified.
+ if (D.isFunctionDefinition()) {
+ // Qualified friend function definition.
+ if (SS.isNotEmpty()) {
+ // FIXME: We should only do this if the scope specifier names the
+ // innermost enclosing namespace; otherwise the fixit changes the
+ // meaning of the code.
+ SemaDiagnosticBuilder DB =
+ Diag(SS.getRange().getBegin(), diag::err_qualified_friend_def);
+
+ DB << SS.getScopeRep();
+ if (DC->isFileContext())
+ DB << FixItHint::CreateRemoval(SS.getRange());
----------------
a-tarasyuk wrote:
@mizvekov, thanks for the feedback. I've added the requested changes.
https://github.com/llvm/llvm-project/pull/191268
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits