Modify

Ticket #2534 (closed Bugs: fixed)

Opened 5 years ago

Last modified 5 years ago

Removing gcc warning

Reported by: richard@… Owned by: chris_kohlhoff
Milestone: Boost 1.38.0 Component: asio
Version: Boost 1.37.0 Severity: Cosmetic
Keywords: gcc warning Cc:

Description

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.

Attachments

Change History

comment:1 Changed 5 years ago by peter _dot_ schneider _dot_ 127 _at_ googlemail _dot_ com

  • Keywords gcc warning added
  • Severity changed from Problem to Cosmetic

"confirm" bjam-output of my project:

...patience...
...found 1105 targets...
...updating 3 targets...
gcc.compile.c++ bin/gcc-4.3.2/release/serialsap.o
In file included from /usr/local/include/boost-1_37/boost/asio/detail/select_interrupter.hpp:24,
                 from /usr/local/include/boost-1_37/boost/asio/detail/epoll_reactor.hpp:42,
                 from /usr/local/include/boost-1_37/boost/asio/impl/io_service.ipp:25,
                 from /usr/local/include/boost-1_37/boost/asio/io_service.hpp:550,
                 from /usr/local/include/boost-1_37/boost/asio/basic_io_object.hpp:20,
                 from /usr/local/include/boost-1_37/boost/asio/basic_socket.hpp:24,
                 from /usr/local/include/boost-1_37/boost/asio/basic_datagram_socket.hpp:25,
                 from /usr/local/include/boost-1_37/boost/asio.hpp:20,
                 from serialsap.h:8,
                 from serialsap.cpp:1:
/usr/local/include/boost-1_37/boost/asio/detail/eventfd_select_interrupter.hpp: In member function ‘void boost::asio::detail::eventfd_select_interrupter::interrupt()’:
/usr/local/include/boost-1_37/boost/asio/detail/eventfd_select_interrupter.hpp:89: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’, declared with attribute warn_unused_result
In file included from /usr/local/include/boost-1_37/boost/asio/detail/select_interrupter.hpp:25,
                 from /usr/local/include/boost-1_37/boost/asio/detail/epoll_reactor.hpp:42,
                 from /usr/local/include/boost-1_37/boost/asio/impl/io_service.ipp:25,
                 from /usr/local/include/boost-1_37/boost/asio/io_service.hpp:550,
                 from /usr/local/include/boost-1_37/boost/asio/basic_io_object.hpp:20,
                 from /usr/local/include/boost-1_37/boost/asio/basic_socket.hpp:24,
                 from /usr/local/include/boost-1_37/boost/asio/basic_datagram_socket.hpp:25,
                 from /usr/local/include/boost-1_37/boost/asio.hpp:20,
                 from serialsap.h:8,
                 from serialsap.cpp:1:
/usr/local/include/boost-1_37/boost/asio/detail/pipe_select_interrupter.hpp: In member function ‘void boost::asio::detail::pipe_select_interrupter::interrupt()’:
/usr/local/include/boost-1_37/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
gcc.compile.c++ bin/gcc-4.3.2/release/protocol.o
gcc.link bin/gcc-4.3.2/release/foo
...updated 3 targets...

Only occurs on release-mode, debug-mode works fine.

gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
...
et=x86_64-linux-gnu
Thread model: posix
gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu11)

not important but would be nice to fix..

MfG

comment:2 follow-up: ↓ 5 Changed 5 years ago by anonymous

This happens also in boost_1_37_0/boost/asio/detail/eventfd_select_interrupter.hpp.

Is the workaround suggested here safe? The warning is there for a good reason, I presume.

These are my details:

uname -a

Linux compilator 2.6.27-9-server #1 SMP Thu Nov 20 22:53:41 UTC 2008 i686 GNU/Linux

g++ -c -o myxxxfile.o -O3 -I../boost_1_37_0/ -MP -MD myxxxfile.cpp
In file included from ../boost_1_37_0/boost/asio/detail/select_interrupter.hpp:24,
                 from ../boost_1_37_0/boost/asio/detail/epoll_reactor.hpp:42,
                 from ../boost_1_37_0/boost/asio/impl/io_service.ipp:25,
                 from ../boost_1_37_0/boost/asio/io_service.hpp:550,
                 from ../boost_1_37_0/boost/asio/basic_io_object.hpp:20,
                 from ../boost_1_37_0/boost/asio/basic_socket.hpp:24,
                 from ../boost_1_37_0/boost/asio/basic_datagram_socket.hpp:25,
                 from ../boost_1_37_0/boost/asio.hpp:20,
                 from stdafx.h:22,
                 from myxxxfile.cpp:1:
../boost_1_37_0/boost/asio/detail/eventfd_select_interrupter.hpp: In member function 'void boost::asio::detail::eventfd_select_interrupter::interrupt()':
../boost_1_37_0/boost/asio/detail/eventfd_select_interrupter.hpp:89: warning: ignoring return value of 'ssize_t write(int, const void*, size_t)', declared with attribute warn_unused_result

comment:3 Changed 5 years ago by chris_kohlhoff

  • Status changed from new to closed
  • Resolution set to fixed

(In [50946]) Suppress unused result warning. Fixes #2534.

comment:4 Changed 5 years ago by chris_kohlhoff

(In [51004]) Merged revisions 50943-50950,50961-50964,50987 via svnmerge from  https://svn.boost.org/svn/boost/trunk

........

r50943 | chris_kohlhoff | 2009-02-01 22:37:18 +1100 (Sun, 01 Feb 2009) | 2 lines

Need to specify socket lib to link correctly on QNX. Fixes #2504.

........

r50944 | chris_kohlhoff | 2009-02-01 22:42:09 +1100 (Sun, 01 Feb 2009) | 2 lines

Use correct size for IP_MULTICAST_LOOP option on QNX. Fixes #2530.

........

r50945 | chris_kohlhoff | 2009-02-01 22:57:01 +1100 (Sun, 01 Feb 2009) | 2 lines

Improve warning message when _WIN32_WINNT is not correctly defined. Fixes #2541.

........

r50946 | chris_kohlhoff | 2009-02-01 23:28:12 +1100 (Sun, 01 Feb 2009) | 2 lines

Suppress unused result warning. Fixes #2534.

........

r50947 | chris_kohlhoff | 2009-02-01 23:41:01 +1100 (Sun, 01 Feb 2009) | 3 lines

Ensure arguments to windows::overlapped_ptr::complete() are passed through to the completion handler. Fixes #2614.

........

r50948 | chris_kohlhoff | 2009-02-01 23:50:08 +1100 (Sun, 01 Feb 2009) | 2 lines

Add include of <cstring> to fix a compile error on Solaris 10. Fixes #2607.

........

r50949 | chris_kohlhoff | 2009-02-02 00:25:05 +1100 (Mon, 02 Feb 2009) | 3 lines

Clear the last error following a successful Windows API call, since some socket providers may leave last error set even when the call succeeds.

........

r50950 | chris_kohlhoff | 2009-02-02 00:42:33 +1100 (Mon, 02 Feb 2009) | 2 lines

Fix errors in SSL overview and add a note about handshaking. Fixes #2617 and #2619.

........

r50961 | chris_kohlhoff | 2009-02-02 17:18:59 +1100 (Mon, 02 Feb 2009) | 2 lines

Use a pipe if eventfd is not supported at runtime. Fixes #2683.

........

r50962 | chris_kohlhoff | 2009-02-02 18:06:00 +1100 (Mon, 02 Feb 2009) | 2 lines

Add link to asio wiki.

........

r50963 | chris_kohlhoff | 2009-02-02 20:36:11 +1100 (Mon, 02 Feb 2009) | 4 lines

Use the workaround syntax for specifying a return type with boost::bind. Needed for the SSL support to work on some older compilers (in particular, g++ 3.4.5 as used with MinGW).

........

r50964 | chris_kohlhoff | 2009-02-02 20:37:10 +1100 (Mon, 02 Feb 2009) | 2 lines

Update asio version number.

........

r50987 | chris_kohlhoff | 2009-02-03 22:00:39 +1100 (Tue, 03 Feb 2009) | 2 lines

Fix generated documentation where the overloads of a function have different brief descriptions.

........

comment:5 in reply to: ↑ 2 Changed 5 years ago by anonymous

Replying to anonymous:

Is the workaround suggested here safe? The warning is there for a good reason, I presume.

AFAIK, the result of a write() should always be checked: the socket or NFS may have gone down, the drive could be full, etc. If this case is just debugging information, or some kind of optional output, ignoring the status might be fine, but IMHO it needs comments to explicitly explain why it is safe.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.