Modify

Opened 6 years ago

Closed 5 years ago

#6118 closed Bugs (fixed)

Uuid random_generator compiles with warnings by GCC

Reported by: Vasily Sukhanov <basil@…> Owned by: Andy Tompkins
Milestone: To Be Determined Component: uuid
Version: Boost 1.47.0 Severity: Problem
Keywords: warning gcc Cc: jonathan.jones@…

Description

uuids::random_generator constructor emits warning when compiled with GCC:

g++ -O2 -Wall -Werror uuidTest.cpp

On Linux x86_64, gcc 4.5.2 output is

/home/vasily/boost_1_47_0/boost/uuid/seed_rng.hpp: In member function ‘void boost::uuids::detail::seed_rng::sha1_random_digest_()’: /home/vasily/boost_1_47_0/boost/uuid/seed_rng.hpp:152:53: error: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result

Cross gcc 4.5.3 (Linux -> Solaris) and gcc 4.6.1 (Linux -> AIX) produce

In file included from testBoostUuid.cpp:3:0: /emc/sukhav/cross/boost_1_47_0/boost/uuid/seed_rng.hpp: In constructor ‘boost::uuids::basic_random_generator<UniformRandomNumberGenerator?>::basic_random_generator() [with UniformRandomNumberGenerator? = boost::random::mersenne_twister_engine<unsigned int, 32ul, 624ul, 397ul, 31ul, 2567483615u, 11ul, 4294967295u, 7ul, 2636928640u, 15ul, 4022730752u, 18ul, 1812433253u>]’: /emc/sukhav/cross/boost_1_47_0/boost/uuid/seed_rng.hpp:243:34: error: ‘end.boost::uuids::detail::generator_iterator<boost::uuids::detail::seed_rng>::m_value’ may be used uninitialized in this function [-Werror=uninitialized]

Latter warning is regression. Compilation passes with boost 1.46.1. Probably, it's caused by some changes in Random library.

Attachments (1)

uuidTest.cpp (109 bytes) - added by Vasily Sukhanov <basil@…> 6 years ago.
test program

Download all attachments as: .zip

Change History (15)

Changed 6 years ago by Vasily Sukhanov <basil@…>

Attachment: uuidTest.cpp added

test program

comment:1 Changed 6 years ago by Vasily Sukhanov <basil@…>

Keywords: gcc added

comment:2 Changed 6 years ago by anonymous

What about casting to void the call to fread?

(void) fread(...)

This should suppress the warning without adding the extra cost to check the value returned by fread.

Otherwise, there is a patch that check this value here: http://boost.2283326.n4.nabble.com/PATCH-1-2-Fixed-warning-ignoring-return-value-of-size-t-fread-void-size-t-size-t-FILE-td3145963.html with the disadvantage of adding another warning when suppressing the BOOST_ASSERT.

comment:3 Changed 6 years ago by Andy Tompkins

Please allow me to rephrase.

As it is, one gets the warning that the return value of std::fread is ignored.

If it is changed to:

size_t not_used = std::fread( ... );


then one gets the warning that not_used is an unused variable

but the following will have no warnings?:

(void) fread( ... );

I checked this into trunk (commit 76007). Please let me know if this does indeed suppress all warnings.

comment:4 Changed 6 years ago by Vasily Sukhanov <basil@…>

Doesn't solve problem. GCC 4.5.2 reports

cc1plus: warnings being treated as errors In file included from /home/vasily/boost_1_47_0/boost/uuid/random_generator.hpp:12:0,

from uuidTest.cpp:1:

/home/vasily/boost_1_47_0/boost/uuid/seed_rng.hpp: In member function ‘void boost::uuids::detail::seed_rng::sha1_random_digest_()’: /home/vasily/boost_1_47_0/boost/uuid/seed_rng.hpp:152:51: error: value computed is not used /home/vasily/boost_1_47_0/boost/uuid/seed_rng.hpp:152:51: error: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result

I am concerned more about second warning on Solaris and AIX.

comment:5 Changed 6 years ago by Andy Tompkins

This random number generator is slow. That is why it is only used to seed a faster random number generator. Therefore I don't believe that the cost of an extra assignment or two will be significant. I checked in the following (trunk commit 76076):

size_t not_used = 0;
not_used = fread( ... );

Does this get rid of all the warnings?

comment:6 Changed 6 years ago by Vasily Sukhanov <basil@…>

Compilation passes with gcc 4.5, but fails in 4.6

/emc/sukhav/cross/boost_1_47_0/boost/uuid/seed_rng.hpp:152:15: error: variable ‘not_used’ set but not used [-Werror=unused-but-set-variable]

-Wunused-but-set-variable is new warning introduced in 4.6 branch.

comment:7 Changed 6 years ago by Andy Tompkins

Changed

not_used = fread( ... );

to

not_used += fread( ... );

Does this get rid of all the warnings?

comment:8 Changed 6 years ago by Andy Tompkins

Forgot to add that I checked this into trunk revision 77049.

comment:9 Changed 6 years ago by Vasily Sukhanov <basil@…>

Looks like you fixed warning on Linux. But you haven't proposed a fix for the second one (AIX/Solaris). At boost/uuid/seed_rng.hpp:244 there is default-initialized generator_iterator. But generator_iterator::generator_iterator() leaves generator_iterator::m_value uninitialized. I reproduced with boost 1.48.

comment:10 Changed 6 years ago by markus@…

Happy it's fixed, but I think a clearer fix would be:

inline void ignore_size(size_t s){} ... ignore_size(std::fread(...));

This won't ever generate instructions or be 'outed' by a compiler as a null operation.

comment:11 Changed 5 years ago by Jonathan Jones <jonathan.jones@…>

Cc: jonathan.jones@… added

comment:12 Changed 5 years ago by benjamin.mahler@…

Any update on fixing the second warning?

end.boost::uuids::detail::generator_iterator<boost::uuids::detail::seed_rng>::m_value' is used uninitialized in this function

comment:13 Changed 5 years ago by Andy Tompkins

I've checked in the ignore_size suggestion in the hopes that it will get rid of all warnings.

I've also checked a fix for the second warning.

Both rev 80501

comment:14 Changed 5 years ago by Andy Tompkins

Resolution: fixed
Status: newclosed

checked in release - changeset #80846

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Andy Tompkins.
The resolution will be deleted.

Add Comment


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

 
Note: See TracTickets for help on using tickets.