Boost C++ Libraries: Ticket #11927: optional_test_swap.cpp: In C++11 mode, std::swap should have a noexcept specification https://svn.boost.org/trac10/ticket/11927 <p> Compiling libs/optional/test/optional_test_swap.cpp with Oracle Solaris Studio 12.5 in C++11 mode, we see the following error: "../libs/optional/test/optional_test_swap.cpp", line 239: Error: The prior declaration for std::swap&lt;optional_swap_test::class_whose_default_ctor_should_not_be_used&gt;(optional_swap_test::class_whose_default_ctor_should_not_be_used&amp;, optional_swap_test::class_whose_default_ctor_should_not_be_used&amp;) has an exception specification. "../libs/optional/test/optional_test_swap.cpp", line 245: Error: The prior declaration for std::swap&lt;optional_swap_test::class_without_default_ctor&gt;(optional_swap_test::class_without_default_ctor&amp;, optional_swap_test::class_without_default_ctor&amp;) has an exception specification. 2 Error(s) detected. </p> <p> See: <a href="http://www.boost.org/development/tests/develop/developer/output/oracle-intel-S2-12-5-cpp11-boost-bin-v2-libs-optional-test-optional_test_swap-test-sun-12-5_cpp11-release-threading-multi.html">http://www.boost.org/development/tests/develop/developer/output/oracle-intel-S2-12-5-cpp11-boost-bin-v2-libs-optional-test-optional_test_swap-test-sun-12-5_cpp11-release-threading-multi.html</a> </p> <p> In C++03, the std::swap template does not have an exception specification. In C++11, it has a noexcept specification. </p> <p> This seems to be a violation of the standard. 15.4[except.spec]p5: ===== If any declaration of a function has an exception-specification that is not a noexcept-specification allowing all exceptions, all declarations, including the definition and any explicit specialization, of that function shall have a compatible exception-specification. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11927 Trac 1.4.3 Aparna Kumta <aparna.kumta@…> Wed, 20 Jan 2016 19:19:24 GMT <link>https://svn.boost.org/trac10/ticket/11927#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11927#comment:1</guid> <description> <p> PR submitted. <a class="ext-link" href="https://github.com/boostorg/optional/pull/17"><span class="icon">​</span>https://github.com/boostorg/optional/pull/17</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 15 Feb 2016 09:04:09 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11927#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11927#comment:2</guid> <description> <p> In C++11 std::swap has the following noexcept specification (20.2.2 [utility.swap]): </p> <pre class="wiki">noexcept(is_nothrow_move_constructible&lt;T&gt;::value &amp;&amp; is_nothrow_move_assignable&lt;T&gt;::value </pre><p> Because <code>optional_swap_test::class_without_default_ctor</code> has a throwing move assignment, therefore the non-specialized instantiation of std::swap for <code>class_without_default_ctor</code> is <code>noexcept(false)</code>. The explicit specialization in file <code>optional_test_swap.cpp</code> is correct not to provide <code>noexcept</code> specification. </p> <p> My guess is that the compiler gets the <code>is_nothrow_move_assignable</code> wrong. </p> </description> <category>Ticket</category> </item> </channel> </rss>