Boost C++ Libraries: Ticket #9740: "-ftrapv" + multiprecision results in crash at startup https://svn.boost.org/trac10/ticket/9740 <p> If the following file is compiled with g++ or clang++ <em>without</em> using the "-ftrapv" flag, it runs fine, irrespective of which lines are commented out. </p> <p> If we compile <em>with</em> "-ftrapv", with either of the <em>causes crash</em> lines uncommented, then the program will crash on start-up, before even entering the "main" function. (The crashy code lives in a function which is never called.) </p> <p> This is true of both g++ and clang++. </p> <p> I am using Boost 1.55, g++ 4.8.1, clang 3.2, on Mint GNU/Linux, x86-64. </p> <p> The -ftrapv flag ( described in gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Code-Gen-Options.html#index-ftrapv-2326 (spam-detection forced me to sabotage the link) ) <em>generates traps for signed overflow on addition, subtraction, multiplication operations</em>. </p> <pre class="wiki">#include &lt;boost/multiprecision/cpp_dec_float.hpp&gt; #include &lt;boost/version.hpp&gt; #if ( BOOST_VERSION != 105500 ) #error Boost 1.55 please #endif void neverCalled() { //boost::multiprecision::cpp_dec_float_100 e; // ok //boost::multiprecision::cpp_dec_float_100 f = 42; // ok //boost::multiprecision::cpp_dec_float_100 g = 42.0f; // causes crash if -ftrapv is used boost::multiprecision::cpp_dec_float_100 h = 42.0; // causes crash if -ftrapv is used } int main() { return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9740 Trac 1.4.3 MaxBarraclough Tue, 04 Mar 2014 16:58:16 GMT attachment set https://svn.boost.org/trac10/ticket/9740 https://svn.boost.org/trac10/ticket/9740 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">screenshot.png</span> </li> </ul> <p> Screenshot of example code being compiled and run </p> Ticket John Maddock Thu, 06 Mar 2014 09:08:02 GMT <link>https://svn.boost.org/trac10/ticket/9740#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9740#comment:1</guid> <description> <p> Confirmed - investigating. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Sat, 08 Mar 2014 10:59:25 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9740#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9740#comment:2</guid> <description> <p> Partial fix here: <a class="ext-link" href="https://github.com/boostorg/multiprecision/commit/bdacea2934e13dd5bab52576525efaa41bf15334"><span class="icon">​</span>https://github.com/boostorg/multiprecision/commit/bdacea2934e13dd5bab52576525efaa41bf15334</a> </p> <p> This still doesn't get all the tests passing with -ftrapv but it's much better than it was (and fixes the original test cases). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Sun, 09 Mar 2014 12:52:16 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/9740#comment:3 https://svn.boost.org/trac10/ticket/9740#comment:3 <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> Completed fixes: <a class="ext-link" href="https://github.com/boostorg/multiprecision/commit/3317ee0d4a99b4cb8fd467ef9304320c02952141"><span class="icon">​</span>https://github.com/boostorg/multiprecision/commit/3317ee0d4a99b4cb8fd467ef9304320c02952141</a> </p> <p> That gets all of our tests running with -ftrapv, which is not to say there may not be other hidden traps here and there. </p> Ticket