The following code snippet:
struct a
{
[[nodiscard]] friend int b();
};
Produces this error when compiling on clang++ (trunk 342102)
with -std=c++17
:
<source>:3:5: error: an attribute list cannot appear here
[[nodiscard]] friend int b();
^~~~~~~~~~~~~
Removing friend
or adding a body to b
prevents the error.
g++ (trunk)
compiles the code just fine.
Live example on godbolt: https://gcc.godbolt.org/z/ttTDuZ
Is this a
clang++
bug? Or is there some rule in the Standard that makes this code ill-formed?If
clang++
is correct, what's the proper way of marking afriend
member function as[[nodiscard]]
?