[shared_ptr] gcc-warnings in yield_k.hpp

Hi ! Peter Dimov commited some refacturings for shared_ptr last weekend. One commit triggered the following warning from gcc-4.2: In file included from yield_k_test.cpp:12: $BOOST_ROOT/boost/boost/detail/yield_k.hpp: In function 'void boost::detail::yield(unsigned int)': $BOOST_ROOT/boost/detail/yield_k.hpp:114: warning: missing initializer for member 'timespec::tv_nsec' This is gcc-4.2 on SuSE-10.3 and Kubuntu Hardy. We compile our code with -Wextra. Adding -Wextra to the compile flags of the yield_k test in libs/smart_ptr/test shows this warning in the regression test. I've got a small fix attached which (hopefully) initialises "rqtp" completely in the initialiser list and removes the (hopefully) redundant assignments. I've manually run the regression test and they pass. I'm unsure if this is the right test. Comments ? Okay to commit ? Yours, Jürgen -- * Dipl.-Math. Jürgen Hunold ! Ingenieurgesellschaft für * voice: ++49 511 262926 57 ! Verkehrs- und Eisenbahnwesen mbH * fax : ++49 511 262926 99 ! Lister Straße 15 * juergen.hunold@ivembh.de ! www.ivembh.de * * Geschäftsführer: ! Sitz des Unternehmens: Hannover * Prof. Dr.-Ing. Thomas Siefer ! Amtsgericht Hannover, HRB 56965 * PD Dr.-Ing. Alfons Radtke !

Juergen Hunold: ...
I've got a small fix attached which (hopefully) initialises "rqtp" completely in the initialiser list and removes the (hopefully) redundant assignments.
else { - struct timespec rqtp = { 0 }; + struct timespec rqtp = { 0, 1000 }; - rqtp.tv_sec = 0; - rqtp.tv_nsec = 1000; - nanosleep( &rqtp, 0 ); } POSIX says that struct timespec has at least the members tv_sec and tv_nsec, but it doesn't guarantee their order or placement. Does struct timespec rqtp = {}; still emit the warnings?

Hi Peter ! On Monday 21 April 2008, Peter Dimov wrote:
POSIX says that struct timespec has at least the members tv_sec and tv_nsec, but it doesn't guarantee their order or placement.
oops, I just looked at /usr/include/time.h :-((
Does
struct timespec rqtp = {};
still emit the warnings?
Quick test shows: $BOOST_ROOT/boost/boost/detail/yield_k.hpp: In function 'void boost::detail::yield(unsigned int)': $BOOST_ROOT/boost/boost/detail/yield_k.hpp:114: warning: missing initializer for member 'timespec::tv_sec' $BOOST_ROOT//boost/boost/detail/yield_k.hpp:114: warning: missing initializer for member 'timespec::tv_nsec' Actually this gets worse :-(( Omitting the initialiser list works: Index: yield_k.hpp =================================================================== --- yield_k.hpp (revision 44703) +++ yield_k.hpp (working copy) @@ -111,7 +111,7 @@ } else { - struct timespec rqtp = { 0 }; + struct timespec rqtp; rqtp.tv_sec = 0; rqtp.tv_nsec = 1000; Thanks for the quick response ! Yours, Jürgen -- * Dipl.-Math. Jürgen Hunold ! Ingenieurgesellschaft für * voice: ++49 511 262926 57 ! Verkehrs- und Eisenbahnwesen mbH * fax : ++49 511 262926 99 ! Lister Straße 15 * juergen.hunold@ivembh.de ! www.ivembh.de * * Geschäftsführer: ! Sitz des Unternehmens: Hannover * Prof. Dr.-Ing. Thomas Siefer ! Amtsgericht Hannover, HRB 56965 * PD Dr.-Ing. Alfons Radtke !

Juergen Hunold:
Does
struct timespec rqtp = {};
still emit the warnings?
...
Actually this gets worse :-((
Then we'll have to go with - struct timespec rqtp = { 0 }; + struct timespec rqtp = { 0, 0 }; and live with the redundant initializations. GCC can be pretty annoying at times. Does anybody actually write {} by mistake? <rolls eyes> :-)

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Monday 21 April 2008 16:59 pm, Peter Dimov wrote:
Juergen Hunold:
Does
struct timespec rqtp = {};
still emit the warnings?
...
Actually this gets worse :-((
Then we'll have to go with
- struct timespec rqtp = { 0 }; + struct timespec rqtp = { 0, 0 };
and live with the redundant initializations. GCC can be pretty annoying at times. Does anybody actually write {} by mistake? <rolls eyes> :-)
Well, the help describing -Wextra does say: "... warn about constructions that users generally do not consider questionable ..." This is kind of trivial, but I'm curious why not just omit the initialization entirely, since you set the members individually anyways? Or, you could memset the whole struct to zero. - -- Frank -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFIDQTD5vihyNWuA4URAgaoAKCxUPP7rc9dV/MuXF1AjujB+RsQngCgnp/2 MCbZ8HpgtitVZyFhDIAP/mw= =qHbM -----END PGP SIGNATURE-----

Hi Peter ! On Monday 21 April 2008, Peter Dimov wrote:
Juergen Hunold:
Actually this gets worse :-((
Then we'll have to go with
- struct timespec rqtp = { 0 }; + struct timespec rqtp = { 0, 0 };
and live with the redundant initializations. GCC can be pretty annoying at times. Does anybody actually write {} by mistake? <rolls eyes> :-)
Well, I try not to ;-) Thanks for the fix with the explanation. Yours, Jürgen -- * Dipl.-Math. Jürgen Hunold ! Ingenieurgesellschaft für * voice: ++49 511 262926 57 ! Verkehrs- und Eisenbahnwesen mbH * fax : ++49 511 262926 99 ! Lister Straße 15 * juergen.hunold@ivembh.de ! www.ivembh.de * * Geschäftsführer: ! Sitz des Unternehmens: Hannover * Prof. Dr.-Ing. Thomas Siefer ! Amtsgericht Hannover, HRB 56965 * PD Dr.-Ing. Alfons Radtke !
participants (3)
-
Frank Mori Hess
-
Juergen Hunold
-
Peter Dimov