Bug 40614 - no -Werror= for attribute warn_unused_result
Summary: no -Werror= for attribute warn_unused_result
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.3
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2009-07-02 05:35 UTC by esigra
Modified: 2009-07-10 07:29 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-07-02 11:33:27


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description esigra 2009-07-02 05:35:13 UTC
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).
Comment 1 Richard Biener 2009-07-02 11:33:27 UTC
Confirmed.
Comment 2 Manuel López-Ibáñez 2009-07-02 23:41:21 UTC
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;
Comment 3 Manuel López-Ibáñez 2009-07-10 07:27:49 UTC
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

Comment 4 Manuel López-Ibáñez 2009-07-10 07:29:19 UTC
FIXED in GCC 4.5