PR41991: Accept attributes on defaulted and deleted friends.

Attributes are permitted on friend definitions, but we only checked for
a proper function body, not for the =default / =delete cases.
This commit is contained in:
Richard Smith 2020-01-30 17:42:17 -08:00
parent 1f3f8c369a
commit 5ae6554a1d
3 changed files with 11 additions and 1 deletions

View File

@ -2716,7 +2716,7 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
// C++11 [dcl.attr.grammar] p4: If an attribute-specifier-seq appertains
// to a friend declaration, that declaration shall be a definition.
if (DeclaratorInfo.isFunctionDeclarator() &&
DefinitionKind != FDK_Definition && DS.isFriendSpecified()) {
DefinitionKind == FDK_Declaration && DS.isFriendSpecified()) {
// Diagnose attributes that appear before decl specifier:
// [[]] friend int foo();
ProhibitAttributes(FnAttrs);

View File

@ -21,3 +21,7 @@ void baz() = delete;
struct quux {
int quux() = default; // expected-error{{constructor cannot have a return type}}
};
struct attrs {
[[noreturn]] friend void deleted_with_attrs() = delete;
};

View File

@ -16,3 +16,9 @@ void f(X<0> x0, X<1> x1) {
X<3> e = x0 < x0 <=> x0 << x0;
X<3> f = x0 << x0 <=> x0 < x0; // expected-warning {{overloaded operator << has higher precedence than comparison operator}} expected-note 2{{}}
}
struct PR41991 {
[[nodiscard]] friend bool operator==(const PR41991&, const PR41991&) = default;
[[nodiscard]] friend bool operator!=(const PR41991&, const PR41991&) = delete;
[[nodiscard]] friend bool operator<(const PR41991&, const PR41991&); // expected-error {{an attribute list cannot appear here}}
};