There is no way to get an error for ignoring the result of a function with attribute warn_unused_result. There should be something like -Werror=unused-return-value (or attribute error_unused_result).
Confirmed.
We can add an option Wunused-result that controls the warnings. Wno-unused-result and -Werror=unused-result will then work as expected. Index: gcc/c-common.c =================================================================== --- gcc/c-common.c (revision 149197) +++ gcc/c-common.c (working copy) @@ -8258,13 +8258,14 @@ c_warn_unused_result (gimple_seq seq) location_t loc = gimple_location (g); if (fdecl) - warning (0, "%Hignoring return value of %qD, " - "declared with attribute warn_unused_result", - &loc, fdecl); + warning_at (loc, OPT_Wunused_result, + "ignoring return value of %qD, " + "declared with attribute warn_unused_result", + fdecl); else - warning (0, "%Hignoring return value of function " - "declared with attribute warn_unused_result", - &loc); + warning_at (loc, OPT_Wunused_result, + "ignoring return value of function " + "declared with attribute warn_unused_result"); } break;
Subject: Bug 40614 Author: manu Date: Fri Jul 10 07:27:32 2009 New Revision: 149458 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149458 Log: 2009-07-10 Manuel López-Ibáñez <manu@gcc.gnu.org> PR 25509 PR 40614 * c.opt (Wunused-result): New. * doc/invoke.texi: Document it. * c-common.c (c_warn_unused_result): Use it. testsuite/ * g++.dg/warn/unused-result1-Werror.c: New. Added: trunk/gcc/testsuite/g++.dg/warn/unused-result1-Werror.c Modified: trunk/gcc/ChangeLog trunk/gcc/c-common.c trunk/gcc/c.opt trunk/gcc/doc/invoke.texi trunk/gcc/testsuite/ChangeLog
FIXED in GCC 4.5