From af5f5e793d0f7301e5e864931a9c91fb9736387f Mon Sep 17 00:00:00 2001 From: manu Date: Fri, 10 Jul 2009 07:27:32 +0000 Subject: [PATCH] =?utf8?q?2009-07-10=20=20Manuel=20L=C3=B3pez-Ib=C3=A1?= =?utf8?q?=C3=B1ez=20=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@149458 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 8 ++++++++ gcc/c-common.c | 6 ++++-- gcc/c.opt | 4 ++++ gcc/doc/invoke.texi | 9 ++++++++- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/warn/unused-result1-Werror.c | 10 ++++++++++ 6 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/unused-result1-Werror.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 253b5dedf57..4c95fb363ba 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2009-07-10 Manuel López-Ibáñez + + 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 * targhooks.c (default_target_can_inline_p): Rename from diff --git a/gcc/c-common.c b/gcc/c-common.c index 1c883d15308..20dac6b2ef4 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -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; diff --git a/gcc/c.opt b/gcc/c.opt index e8a9a31a382..5ee9a1348d4 100644 --- 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 diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 7742623b5b5..cb51dfbaf15 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 48711da3da0..651afbf6435 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2009-07-10 Manuel López-Ibáñez + + PR 25509 + PR 40614 + * g++.dg/warn/unused-result1-Werror.c: New. + 2009-07-10 Paul Thomas 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 index 00000000000..033d707778c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/unused-result1-Werror.c @@ -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" } +}; -- 2.11.0