re PR c/25509 (can't disable __attribute__((warn_unused_result)))
authorManuel López-Ibáñez <manu@gcc.gnu.org>
Fri, 10 Jul 2009 07:27:32 +0000 (07:27 +0000)
committerManuel López-Ibáñez <manu@gcc.gnu.org>
Fri, 10 Jul 2009 07:27:32 +0000 (07:27 +0000)
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.

From-SVN: r149458

gcc/ChangeLog
gcc/c-common.c
gcc/c.opt
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/unused-result1-Werror.c [new file with mode: 0644]

index 253b5dedf579e0f5128bd56bebed4c2ef32451c1..4c95fb363baf70efa863b9da587a3055f6d09dc3 100644 (file)
@@ -1,3 +1,11 @@
+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.
+
 2009-07-09  DJ Delorie  <dj@redhat.com>
 
        * targhooks.c (default_target_can_inline_p): Rename from
index 1c883d15308ed3bf11130a9b9e2379641cadb23d..20dac6b2ef4250caf14454225e7dc18a3098e3fc 100644 (file)
@@ -8266,11 +8266,13 @@ c_warn_unused_result (gimple_seq seq)
              location_t loc = gimple_location (g);
 
              if (fdecl)
-               warning_at (loc, 0, "ignoring return value of %qD, "
+               warning_at (loc, OPT_Wunused_result, 
+                           "ignoring return value of %qD, "
                            "declared with attribute warn_unused_result",
                            fdecl);
              else
-               warning_at (loc, 0, "ignoring return value of function "
+               warning_at (loc, OPT_Wunused_result,
+                           "ignoring return value of function "
                            "declared with attribute warn_unused_result");
            }
          break;
index e8a9a31a382a45a01a28bf195c66da4823a29939..5ee9a1348d448a47d9d832def6fad7efa5b6d4df 100644 (file)
--- a/gcc/c.opt
+++ b/gcc/c.opt
@@ -488,6 +488,10 @@ Wunused-macros
 C ObjC C++ ObjC++ Warning
 Warn about macros defined in the main file that are not used
 
+Wunused-result
+C ObjC C++ ObjC++ Var(warn_unused_result) Init(1) Warning
+Warn if a caller of a function, marked with attribute warn_unused_result, does not use its return value
+
 Wvariadic-macros
 C ObjC C++ ObjC++ Warning
 Do not warn about using variadic macros when -pedantic
index 7742623b5b55c7c3ee6e5e60a278fc721b3e8a67..cb51dfbaf15a4a6eaf308e689eaa1a93eece5bc7 100644 (file)
@@ -260,7 +260,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wsystem-headers  -Wtrigraphs  -Wtype-limits  -Wundef  -Wuninitialized @gol
 -Wunknown-pragmas  -Wno-pragmas -Wunreachable-code @gol
 -Wunsuffixed-float-constants  -Wunused  -Wunused-function @gol
--Wunused-label  -Wunused-parameter  -Wunused-value  -Wunused-variable @gol
+-Wunused-label  -Wunused-parameter -Wno-unused-result -Wunused-value  -Wunused-variable @gol
 -Wvariadic-macros -Wvla @gol
 -Wvolatile-register-var  -Wwrite-strings}
 
@@ -3259,6 +3259,13 @@ Warn whenever a function parameter is unused aside from its declaration.
 To suppress this warning use the @samp{unused} attribute
 (@pxref{Variable Attributes}).
 
+@item -Wno-unused-result
+@opindex Wunused-result
+@opindex Wno-unused-result
+Do not warn if a caller of a function marked with attribute
+@code{warn_unused_result} (@pxref{Variable Attributes}) does not use
+its return value. The default is @option{-Wunused-result}.
+
 @item -Wunused-variable
 @opindex Wunused-variable
 @opindex Wno-unused-variable
index 48711da3da03adc73f534dac99b56d7ef610a496..651afbf6435150d5b881fce31434a6251cf573d8 100644 (file)
@@ -1,3 +1,9 @@
+2009-07-10  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       PR 25509
+       PR 40614
+       * g++.dg/warn/unused-result1-Werror.c: New.
+
 2009-07-10  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/39334
diff --git a/gcc/testsuite/g++.dg/warn/unused-result1-Werror.c b/gcc/testsuite/g++.dg/warn/unused-result1-Werror.c
new file mode 100644 (file)
index 0000000..033d707
--- /dev/null
@@ -0,0 +1,10 @@
+// PR 40614
+// { dg-options "-Werror=unused-result" }
+class QByteArray {
+public:
+  QByteArray(const QByteArray &);
+};
+class QString {
+  QByteArray toLocal8Bit() const __attribute__ ((warn_unused_result));
+  void fooWarnHere() const { toLocal8Bit(); } // { dg-error "ignoring" }
+};