https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79696
Bug ID: 79696 Summary: missing -Wunused-result on calls to malloc() and calloc() Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- When optimization is enabled GCC eliminates calls to malloc, calloc, and aligned_alloc whose result isn't used but it fails to issue a -Wunused-result warning for them. It looks like the reason is that the built-ins are not decorated with attribute warn_unused_result (either in GCC, or, with the exception of realloc, their public declarations in Glibc). $ cat u.c && gcc -O2 -S -Wall -Wextra -Wpedantic -Wunused-result -fdump-tree-optimized=/dev/stdout u.C void f ([[maybe_unused]] int a [[maybe_unused]]) { } ;; Function void f() (_Z1fv, funcdef_no=0, decl_uid=2274, cgraph_uid=0, symbol_order=0) void f() () { <bb 2> [100.00%]: return; } ;; Function void g() (_Z1gv, funcdef_no=4, decl_uid=2276, cgraph_uid=1, symbol_order=1) void g() () { <bb 2> [100.00%]: return; } ;; Function void h() (_Z1hv, funcdef_no=6, decl_uid=2278, cgraph_uid=2, symbol_order=2) void h() () { <bb 2> [100.00%]: return; }