Boost logo

Boost :

Subject: [boost] [asio] Removing gcc warning
From: Richard Smith (richard_at_[hidden])
Date: 2008-11-19 16:12:26


The function

   boost::asio::detail::pipe_select_interrupter::interupt()

in <boost/asio/detail/pipe_select_interrupter.hpp> produces
the following warning in gcc 4.3.2 / glibc 2.8 when compiled
with -O1 or higher. The warning occurs even without any -W
options.

   ./boost/asio/detail/pipe_select_interrupter.hpp:75:
     warning: ignoring return value of ¡ssize_t write(int,
     const void*, size_t)¢, declared with attribute
     warn_unused_result

As the message implies, gcc issues this warning whenever a
function declared with __attribute__((warn_unused_result));
it appears that gcc implicitly places this attribute on
::write as the glibc header doesn't contain it.

A short test case is:

   #include <unistd.h>
   int main() { ::write(1, 0, 0); }

To suppress the warning, the function interupt() function
can be altered as follows:

   #include <boost/concept_check.hpp>

   void interrupt()
   {
     char byte = 0;
     ignore_unused_variable_warning( ::write(write_descriptor_, &byte, 1) );
   }

Is there any chance of making a change along these lines?

Apologies if this is a know issue: a quick search of the
mailing list didn't turn anything up.

--
Richard Smith

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk