以下代码段:
struct a
{
[[nodiscard]] friend int b();
};
在上编译时产生此错误
clang++ (trunk 342102)
具有
-std=c++17
<source>:3:5: error: an attribute list cannot appear here
[[nodiscard]] friend int b();
^~~~~~~~~~~~~
friend
或是加入身体
b
防止错误。
g++ (trunk)
很好地编译了代码。
https://gcc.godbolt.org/z/ttTDuZ