1// Copyright (c) 2023 Andrey Semashev
2//
3// Distributed under the Boost Software License, Version 1.0.
4// (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7// Tests that boost::core::invoke_swap propagates noexcept specification correctly
8
9#include <boost/core/invoke_swap.hpp>
10#include <boost/config.hpp>
11
12#if !defined(BOOST_NO_CXX11_NOEXCEPT) && !defined(BOOST_NO_CXX11_STATIC_ASSERT) && \
13 !(defined(BOOST_GCC) && (BOOST_GCC < 40700))
14
15namespace test_ns {
16
17struct class_with_noexcept_swap
18{
19 static class_with_noexcept_swap& instance() noexcept;
20
21 friend void swap(class_with_noexcept_swap&, class_with_noexcept_swap&) noexcept
22 {
23 }
24};
25
26struct class_with_except_swap
27{
28 static class_with_except_swap& instance() noexcept;
29
30 friend void swap(class_with_except_swap&, class_with_except_swap&)
31 {
32 }
33};
34
35} // namespace test_ns
36
37static_assert(noexcept(boost::core::invoke_swap(left&: test_ns::class_with_noexcept_swap::instance(), right&: test_ns::class_with_noexcept_swap::instance())),
38 "boost::core::invoke_swap for class_with_noexcept_swap should have noexcept specification");
39static_assert(!noexcept(boost::core::invoke_swap(left&: test_ns::class_with_except_swap::instance(), right&: test_ns::class_with_except_swap::instance())),
40 "boost::core::invoke_swap for class_with_except_swap should not have noexcept specification");
41
42#endif // !defined(BOOST_NO_CXX11_NOEXCEPT) && !defined(BOOST_NO_CXX11_STATIC_ASSERT) ...
43

source code of boost/libs/core/test/swap/swap_noexcept.cpp