https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82134
Jeremy R. <llvm at rifkin dot dev> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |llvm at rifkin dot dev --- Comment #7 from Jeremy R. <llvm at rifkin dot dev> --- I have encountered this issue as well and I'm having to work around it. ``` struct S {}; __attribute__((warn_unused_result)) S bar(); void foo() { S s = bar(); } ``` ``` <source>:6:14: warning: ignoring return value of 'S bar()' declared with attribute 'warn_unused_result' [-Wunused-result] 6 | S s = bar(); | ~~~^~ ``` Clang handles this right, gcc does not https://cpp.godbolt.org/z/zoq3756zK I see there is some discussion here about whether warn_unused_result should be applied to a function returning an empty struct. Maybe not, but this comes up with templated code. Interestingly this doesn't happen for [[nodiscard]], it looks like it might only be checked in cvt.cc and c-typecheck.cc instead of tree-cfg.cc where it manifests for warn_unused_result. I have a patch locally to fix this and will submit it.