Fix warning caused by unused-result in bug-atexit3-lib.cc

Message ID 1477659653-9022-1-git-send-email-gftg@linux.vnet.ibm.com
State Superseded
Headers

Commit Message

Gabriel F T Gomes Oct. 28, 2016, 1 p.m. UTC
  The test case dlfcn/bug-atexit3-lib.cc calls write and doesn't check the
result.  When building with GCC 6.2 from IBM's branch, this generates a
warning in 'make check', which is treated as an error.  This patch adds a
return variable to get rid of the warning and of the error.

Tested for powerpc64le.

2016-10-28  Gabriel F. T. Gomes  <gftg@linux.vnet.ibm.com>

	* dlfcn/bug-atexit3-lib.cc (statclass): Assign return of call to
	write (defined with __wur) to unused variable.
---
 dlfcn/bug-atexit3-lib.cc | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
  

Comments

Florian Weimer Oct. 28, 2016, 1:04 p.m. UTC | #1
On 10/28/2016 03:00 PM, Gabriel F. T. Gomes wrote:
> The test case dlfcn/bug-atexit3-lib.cc calls write and doesn't check the
> result.  When building with GCC 6.2 from IBM's branch, this generates a
> warning in 'make check', which is treated as an error.  This patch adds a
> return variable to get rid of the warning and of the error.

You could use write_message from test-skeleton.c instead.  it has a 
proper unused variable guard.

Thanks,
Florian
  
Gabriel F T Gomes Oct. 28, 2016, 1:32 p.m. UTC | #2
On Fri, 28 Oct 2016 15:04:13 +0200
Florian Weimer <fweimer@redhat.com> wrote:

> On 10/28/2016 03:00 PM, Gabriel F. T. Gomes wrote:
> > The test case dlfcn/bug-atexit3-lib.cc calls write and doesn't check the
> > result.  When building with GCC 6.2 from IBM's branch, this generates a
> > warning in 'make check', which is treated as an error.  This patch adds a
> > return variable to get rid of the warning and of the error.  
> 
> You could use write_message from test-skeleton.c instead.  it has a 
> proper unused variable guard.

Is it ok to use write_message in c++ code being built as object?

Thanks,
Gabriel
  
Florian Weimer Oct. 28, 2016, 1:34 p.m. UTC | #3
On 10/28/2016 03:32 PM, Gabriel F. T. Gomes wrote:
> On Fri, 28 Oct 2016 15:04:13 +0200
> Florian Weimer <fweimer@redhat.com> wrote:
>
>> On 10/28/2016 03:00 PM, Gabriel F. T. Gomes wrote:
>>> The test case dlfcn/bug-atexit3-lib.cc calls write and doesn't check the
>>> result.  When building with GCC 6.2 from IBM's branch, this generates a
>>> warning in 'make check', which is treated as an error.  This patch adds a
>>> return variable to get rid of the warning and of the error.
>>
>> You could use write_message from test-skeleton.c instead.  it has a
>> proper unused variable guard.
>
> Is it ok to use write_message in c++ code being built as object?

Oh, right, this probably will not work.  Bummer.

You could copy the function into the .cc file, though.  The unused 
attribute may be needed in the long term.

Florian
  

Patch

diff --git a/dlfcn/bug-atexit3-lib.cc b/dlfcn/bug-atexit3-lib.cc
index 3d01ea8..5a7c454 100644
--- a/dlfcn/bug-atexit3-lib.cc
+++ b/dlfcn/bug-atexit3-lib.cc
@@ -4,11 +4,15 @@  struct statclass
 {
   statclass()
   {
-    write (1, "statclass\n", 10);
+    size_t unused_ret;
+    (void) unused_ret;
+    unused_ret = write (1, "statclass\n", 10);
   }
   ~statclass()
   {
-    write (1, "~statclass\n", 11);
+    size_t unused_ret;
+    (void) unused_ret;
+    unused_ret = write (1, "~statclass\n", 11);
   }
 };