Boost C++ Libraries: Ticket #11826: float128.hpp: too aggressive NOTHROW on converting assignment operator https://svn.boost.org/trac10/ticket/11826 <p> In order to fix another issue, commit <a class="ext-link" href="https://github.com/boostorg/multiprecision/commit/9927d49cb9d87c022c3ac49b3c8d84ce55ab7dc4"><span class="icon">​</span>https://github.com/boostorg/multiprecision/commit/9927d49cb9d87c022c3ac49b3c8d84ce55ab7dc4</a> introduced several unconditional BOOST_NOTHROWs in float128.hpp. In my opinion, at least some of them are problematic, especially for the assignment operator (line 150) and the conversion constructor (line 147). Both support initialization from any type implicitly convertible to the underlying float128_type. However, implicit conversion routines might throw, as demonstrated by the following example program: </p> <pre class="wiki">// g++ -std=c++11 exception_float128.cpp -o exception_float128 -fext-numeric-literals -lquadmath #include &lt;iostream&gt; #include &lt;stdexcept&gt; #include &lt;boost/multiprecision/float128.hpp&gt; struct outer { template &lt;typename T&gt; struct inner { T operator()() const { throw std::runtime_error("Bad stuff happened"); return T{0}; } }; template &lt;typename Target, typename = typename std::enable_if&lt;!std::is_same&lt;Target, const char *&gt;::value&gt;::type&gt; operator Target() const { return inner&lt;Target&gt;()(); } }; int main() { boost::multiprecision::float128 destination; outer source; try { destination = source; } catch (const std::exception &amp;e) { std::cerr &lt;&lt; "caught exception: " &lt;&lt; e.what() &lt;&lt; "\n"; } return 0; } </pre><p> Compiled with recent boost, this code std::terminate's. If BOOST_NOTHROW in float128.hpp:150 is replaced by BOOST_NOEXCEPT_IF(noexcept(std::declval&lt;float128_type&amp;&gt;() = std::declval&lt;const T&amp;&gt;())), the exception is caught as expected. Such conditional noexcept specifiers might be required in some more places, provided there isn't a policy that I am unaware of, which forbids implicit conversion operators to throw. </p> <p> (BTW: the above code is not just a twisted mockup. I hit the problem while developing a conversion library that uses the "template &lt;typename T&gt; operator T()" trick to let the compiler deduce the target type automatically. An appropriate functor is then selected that implements the actual conversion or throws, if no suitable source data is provided.) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11826 Trac 1.4.3 John Maddock Tue, 01 Dec 2015 15:59:48 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/11826#comment:1 https://svn.boost.org/trac10/ticket/11826#comment:1 <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> Thanks, this should now be fixed in <a class="ext-link" href="https://github.com/boostorg/multiprecision/commit/5af45646989df0924baa87b0c19c16f228b8ebfb"><span class="icon">​</span>https://github.com/boostorg/multiprecision/commit/5af45646989df0924baa87b0c19c16f228b8ebfb</a>. </p> Ticket