Skip to content

Commit

Permalink
PR41991: Accept attributes on defaulted and deleted friends.
Browse files Browse the repository at this point in the history
Attributes are permitted on friend definitions, but we only checked for
a proper function body, not for the =default / =delete cases.

(cherry picked from commit 5ae6554)
  • Loading branch information
zygoloid committed Jan 31, 2020
1 parent 800395c commit 0ce7ea7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Parse/ParseDeclCXX.cpp
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Parser/cxx-default-delete.cpp
Expand Up @@ -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;
};
6 changes: 6 additions & 0 deletions clang/test/Parser/cxx2a-spaceship.cpp
Expand Up @@ -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}}
};

0 comments on commit 0ce7ea7

Please sign in to comment.