diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index f872aa3a950c9..09e5c7996fcd5 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -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); diff --git a/clang/test/Parser/cxx-default-delete.cpp b/clang/test/Parser/cxx-default-delete.cpp index 8766d861732e9..6c74937504b0c 100644 --- a/clang/test/Parser/cxx-default-delete.cpp +++ b/clang/test/Parser/cxx-default-delete.cpp @@ -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; +}; diff --git a/clang/test/Parser/cxx2a-spaceship.cpp b/clang/test/Parser/cxx2a-spaceship.cpp index 24cece3eaa9da..f80420f898627 100644 --- a/clang/test/Parser/cxx2a-spaceship.cpp +++ b/clang/test/Parser/cxx2a-spaceship.cpp @@ -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}} +};