[clang] [Clang][Sema] Diagnose friend declarations with enum elaborated-type-specifier in all language modes (PR #80171)
Krystian Stasiowski via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 8 10:25:18 PST 2024
================
@@ -17242,6 +17242,23 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
return true;
}
+ if (TUK == TUK_Friend && Kind == TagTypeKind::Enum) {
+ // C++23 [dcl.type.elab]p4:
+ // If an elaborated-type-specifier appears with the friend specifier as
+ // an entire member-declaration, the member-declaration shall have one
+ // of the following forms:
+ // friend class-key nested-name-specifier(opt) identifier ;
+ // friend class-key simple-template-id ;
+ // friend class-key nested-name-specifier template(opt)
+ // simple-template-id ;
+ //
+ // Since enum is not a class-key, so declarations like "friend enum E;"
+ // are ill-formed. Although CWG2363 reaffirms that such declarations are
+ // invalid, most implementations accept so we issue a pedantic warning.
+ Diag(KWLoc, diag::ext_enum_friend) << FixItHint::CreateRemoval(
----------------
sdkrystian wrote:
@Endilll I added `note_friend_enum` in the most recent commit.
> Wording we settled with for diagnostic message is not the one.
Could you elaborate on what you mean by this? The diagnostic now reads:
> elaborated enum specifier cannot be declared as a friend
Which Aaron seemed to be happy with.
https://github.com/llvm/llvm-project/pull/80171
More information about the cfe-commits
mailing list