https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82134
Bug ID: 82134 Summary: warn_unused_result triggers on empty structs even when they are used Product: gcc Version: 7.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: zackw at panix dot com Target Milestone: --- If a function that returns an empty struct is tagged with attribute warn_unused_result, any call will trigger the warning, even if the return value is (nominally) used. For instance struct Empty {}; extern void use_empty(struct Empty); __attribute__((warn_unused_result)) extern struct Empty make_empty(void); void should_warn(void) { make_empty(); } void shouldnt_warn_1(void) { use_empty(make_empty()); } void shouldnt_warn_2(void) { struct Empty e = make_empty(); use_empty(e); } --> test.c: In function ‘should_warn’: test.c:10:5: warning: ignoring return value of ‘make_empty’, declared with attribute warn_unused_result [-Wunused-result] make_empty(); ^~~~~~~~~~~~ test.c: In function ‘shouldnt_warn_1’: test.c:15:5: warning: ignoring return value of ‘make_empty’, declared with attribute warn_unused_result [-Wunused-result] use_empty(make_empty()); ^~~~~~~~~~~~~~~~~~~~~~~ test.c: In function ‘shouldnt_warn_2’: test.c:20:22: warning: ignoring return value of ‘make_empty’, declared with attribute warn_unused_result [-Wunused-result] struct Empty e = make_empty(); ^~~~~~~~~~~~ with both GCC 6 and GCC 7. (From here: https://stackoverflow.com/questions/46096628/gcc-empty-structs-and-wunused-result)