Modify

Ticket #6118 (closed Bugs: fixed)

Opened 2 years ago

Last modified 19 months ago

Uuid random_generator compiles with warnings by GCC

Reported by: Vasily Sukhanov <basil@…> Owned by: atompkins
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

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

Change History

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

test program

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

  • Keywords gcc added

comment:2 Changed 2 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 2 years ago by atompkins

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 2 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 2 years ago by atompkins

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 2 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 2 years ago by atompkins

Changed

not_used = fread( ... );

to

not_used += fread( ... );

Does this get rid of all the warnings?

comment:8 Changed 2 years ago by atompkins

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

comment:9 Changed 2 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 2 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 22 months ago by Jonathan Jones <jonathan.jones@…>

  • Cc jonathan.jones@… added

comment:12 Changed 20 months 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 20 months ago by atompkins

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 19 months ago by atompkins

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

checked in release - changeset #80846

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.