Boost C++ Libraries: Ticket #6118: Uuid random_generator compiles with warnings by GCC https://svn.boost.org/trac10/ticket/6118 <p> uuids::random_generator constructor emits warning when compiled with GCC: </p> <blockquote class="citation"> <p> g++ -O2 -Wall -Werror uuidTest.cpp<br /> </p> </blockquote> <p> On Linux x86_64, gcc 4.5.2 output is </p> <p> /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 </p> <p> Cross gcc 4.5.3 (Linux -&gt; Solaris) and gcc 4.6.1 (Linux -&gt; AIX) produce </p> <p> 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&lt;<a class="missing wiki">UniformRandomNumberGenerator</a>&gt;::basic_random_generator() [with <a class="missing wiki">UniformRandomNumberGenerator</a> = boost::random::mersenne_twister_engine&lt;unsigned int, 32ul, 624ul, 397ul, 31ul, 2567483615u, 11ul, 4294967295u, 7ul, 2636928640u, 15ul, 4022730752u, 18ul, 1812433253u&gt;]’: /emc/sukhav/cross/boost_1_47_0/boost/uuid/seed_rng.hpp:243:34: error: ‘end.boost::uuids::detail::generator_iterator&lt;boost::uuids::detail::seed_rng&gt;::m_value’ may be used uninitialized in this function [-Werror=uninitialized] </p> <p> Latter warning is regression. Compilation passes with boost 1.46.1. Probably, it's caused by some changes in Random library. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6118 Trac 1.4.3 Vasily Sukhanov <basil@…> Sat, 12 Nov 2011 16:24:31 GMT attachment set https://svn.boost.org/trac10/ticket/6118 https://svn.boost.org/trac10/ticket/6118 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">uuidTest.cpp</span> </li> </ul> <p> test program </p> Ticket Vasily Sukhanov <basil@…> Sat, 12 Nov 2011 16:27:12 GMT keywords changed https://svn.boost.org/trac10/ticket/6118#comment:1 https://svn.boost.org/trac10/ticket/6118#comment:1 <ul> <li><strong>keywords</strong> gcc added </li> </ul> Ticket anonymous Tue, 22 Nov 2011 12:37:42 GMT <link>https://svn.boost.org/trac10/ticket/6118#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6118#comment:2</guid> <description> <p> What about casting to void the call to fread? </p> <div class="wiki-code"><div class="code"><pre><span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="n">fread</span><span class="p">(...)</span> </pre></div></div><p> This should suppress the warning without adding the extra cost to check the value returned by fread. </p> <p> Otherwise, there is a patch that check this value here: <a class="ext-link" href="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"><span class="icon">​</span>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</a> with the disadvantage of adding another warning when suppressing the BOOST_ASSERT. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andy Tompkins</dc:creator> <pubDate>Sat, 17 Dec 2011 02:07:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6118#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6118#comment:3</guid> <description> <p> Please allow me to rephrase.<br /> </p> <p> As it is, one gets the warning that the return value of std::fread is ignored.<br /> </p> <p> If it is changed to:<br /> </p> <pre class="wiki">size_t not_used = std::fread( ... ); </pre><p> <br /> then one gets the warning that <em>not_used</em> is an unused variable<br /> </p> <p> but the following will have no warnings?:<br /> </p> <pre class="wiki">(void) fread( ... ); </pre><p> I checked this into trunk (commit 76007). Please let me know if this does indeed suppress all warnings. </p> </description> <category>Ticket</category> </item> <item> <author>Vasily Sukhanov <basil@…></author> <pubDate>Sat, 17 Dec 2011 12:53:57 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6118#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6118#comment:4</guid> <description> <p> Doesn't solve problem. GCC 4.5.2 reports </p> <p> cc1plus: warnings being treated as errors In file included from /home/vasily/boost_1_47_0/boost/uuid/random_generator.hpp:12:0, </p> <blockquote> <p> from uuidTest.cpp:1: </p> </blockquote> <p> /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 </p> <p> I am concerned more about second warning on Solaris and AIX. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andy Tompkins</dc:creator> <pubDate>Tue, 20 Dec 2011 02:06:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6118#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6118#comment:5</guid> <description> <p> 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): </p> <pre class="wiki">size_t not_used = 0; not_used = fread( ... ); </pre><p> Does this get rid of all the warnings? </p> </description> <category>Ticket</category> </item> <item> <author>Vasily Sukhanov <basil@…></author> <pubDate>Thu, 05 Jan 2012 09:16:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6118#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6118#comment:6</guid> <description> <p> Compilation passes with gcc 4.5, but fails in 4.6 </p> <p> /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] </p> <p> -Wunused-but-set-variable is new warning introduced in 4.6 branch. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andy Tompkins</dc:creator> <pubDate>Fri, 17 Feb 2012 02:27:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6118#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6118#comment:7</guid> <description> <p> Changed </p> <pre class="wiki">not_used = fread( ... ); </pre><p> to </p> <pre class="wiki">not_used += fread( ... ); </pre><p> Does this get rid of all the warnings? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andy Tompkins</dc:creator> <pubDate>Fri, 17 Feb 2012 02:27:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6118#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6118#comment:8</guid> <description> <p> Forgot to add that I checked this into trunk revision 77049. </p> </description> <category>Ticket</category> </item> <item> <author>Vasily Sukhanov <basil@…></author> <pubDate>Mon, 05 Mar 2012 12:02:25 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6118#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6118#comment:9</guid> <description> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <author>markus@…</author> <pubDate>Sun, 18 Mar 2012 06:58:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6118#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6118#comment:10</guid> <description> <p> Happy it's fixed, but I think a clearer fix would be: </p> <p> inline void ignore_size(size_t s){} ... ignore_size(std::fread(...)); </p> <p> This won't ever generate instructions or be 'outed' by a compiler as a null operation. </p> </description> <category>Ticket</category> </item> <item> <author>Jonathan Jones <jonathan.jones@…></author> <pubDate>Fri, 29 Jun 2012 21:10:33 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/6118#comment:11 https://svn.boost.org/trac10/ticket/6118#comment:11 <ul> <li><strong>cc</strong> <span class="trac-author">jonathan.jones@…</span> added </li> </ul> Ticket benjamin.mahler@… Tue, 28 Aug 2012 17:14:48 GMT <link>https://svn.boost.org/trac10/ticket/6118#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6118#comment:12</guid> <description> <p> Any update on fixing the second warning? </p> <p> end.boost::uuids::detail::generator_iterator&lt;boost::uuids::detail::seed_rng&gt;::m_value' is used uninitialized in this function </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andy Tompkins</dc:creator> <pubDate>Wed, 12 Sep 2012 01:17:48 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6118#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6118#comment:13</guid> <description> <p> I've checked in the ignore_size suggestion in the hopes that it will get rid of all warnings. </p> <p> I've also checked a fix for the second warning. </p> <p> Both rev 80501 </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andy Tompkins</dc:creator> <pubDate>Thu, 04 Oct 2012 17:09:28 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6118#comment:14 https://svn.boost.org/trac10/ticket/6118#comment:14 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> checked in release - changeset <a class="missing ticket">#80846</a> </p> Ticket