Boost C++ Libraries: Ticket #9925: operators_test.cpp test_left_shiftable is failing due to invalid parameters https://svn.boost.org/trac10/ticket/9925 <p> In libs/utility/operators_test.cpp, test_left_shiftable is checking whether one random value shifted by a second random value, is the same whether called directly or via the Wrapper2&lt;&gt; and Wrapper1&lt;&gt; template classes. </p> <p> However, according to C++ ISO specification (INCITS/ISO/IEC 14882-2011\[2012\]), section 5.8.2 (which I don't have, but is referenced at http: / / msdn.microsoft.com/en-us/library/336xbhcz.aspx), left-shifting a signed value has undefined behavior (which is much more unpleasant than implementation-defined behavior) if the result doesn't fit in an unsigned value of the same size. </p> <p> With the clang compiler that comes with Xcode 5.1 ("Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)"), the results of such left-shifts are seemingly random - this code: </p> <pre class="wiki">long b1 = 48271; int s = 1291394886; std::cout &lt;&lt; (b1 &lt;&lt; s) &lt;&lt; std::endl; std::cout &lt;&lt; (b1 &lt;&lt; s)&lt;&lt; std::endl; std::cout &lt;&lt; (b1 &lt;&lt; s)&lt;&lt; std::endl; </pre><p> prints three different numbers. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9925 Trac 1.4.3 chris.cooper@… Fri, 18 Apr 2014 18:32:25 GMT <link>https://svn.boost.org/trac10/ticket/9925#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9925#comment:1</guid> <description> <p> This behavior causes the regression test to fail inaccurately. </p> <p> Unfortunately, it's a bit of a pain to easily modify this regression test to limit the input parameters to test_left_shiftable() to ones that will not encounter the compiler's "undefined behavior". Consider removing test_left_shiftable() from test_all() and make a special testing loop that calls it, passing a different set of random numbers guaranteed to be valid left-shift parameters ... </p> </description> <category>Ticket</category> </item> <item> <author>chris.cooper@…</author> <pubDate>Mon, 21 Apr 2014 17:21:26 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9925#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9925#comment:2</guid> <description> <p> The same problem occurs with test_right_shiftable(). </p> </description> <category>Ticket</category> </item> <item> <author>chris.cooper@…</author> <pubDate>Mon, 21 Apr 2014 17:49:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9925#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9925#comment:3</guid> <description> <p> One solution: change the end of test_all() to look like this: </p> <pre class="wiki"> test_incrementable( x1, x2 ); test_decrementable( x1, x2 ); // Make sure the right-hand operator to the shift operator is not out-of-range. if (true_value(y1) &lt; 0) y1 = Y1(-true_value(y1)); unsigned long m1 = sizeof(true_value(x1)) * 8 - 1; if (true_value(y1) &gt; m1) y1 = Y1(true_value(y1) &amp; m1); if (y2 &lt; 0) y2 = -y2; unsigned long m2 = sizeof(true_value(x2)) * 8 - 1; if (y2 &gt; m2) y2 = y2 &amp; m2; test_left_shiftable( x1, y1, x2, y2 ); test_right_shiftable( x1, y1, x2, y2 ); </pre> </description> <category>Ticket</category> </item> <item> <author>Niklas Angare <li51ckf02@…></author> <pubDate>Thu, 26 Jun 2014 21:59:15 GMT</pubDate> <title>owner, component changed https://svn.boost.org/trac10/ticket/9925#comment:4 https://svn.boost.org/trac10/ticket/9925#comment:4 <ul> <li><strong>owner</strong> changed from <span class="trac-author">René Rivera</span> to <span class="trac-author">No-Maintainer</span> </li> <li><strong>component</strong> <span class="trac-field-old">Regression Testing</span> → <span class="trac-field-new">utility</span> </li> </ul> Ticket