// Copyright (C) 2015-2025 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING3. If not see // . #include #if defined(test_std_is_nothrow_swappable) # ifndef __cpp_lib_is_swappable # error "Feature-test macro for is_nothrow_swappable missing" # elif __cpp_lib_is_swappable != 201603 # error "Feature-test macro for is_nothrow_swappable has wrong value" # endif // Test std::is_nothrow_swappable: template using is_nothrow_swappable = std::is_nothrow_swappable; #elif defined(test_std_is_nothrow_swappable_ext) // Test our __is_nothrow_swappable extension: template using is_nothrow_swappable = std::__is_nothrow_swappable; #else # error "Either test_std_is_nothrow_swappable or " \ "test_std_is_nothrow_swappable_ext need to be defined" #endif #include #include #include #include #include #include namespace funny { struct F {}; void swap(F&, F&) = delete; void swap(F(&)[5], F(&)[5]) noexcept; void swap(F(&)[6], F(&)[6]); struct A {}; void swap(A&, A&) noexcept(false); } namespace std { template<> void swap(funny::A&, funny::A&) noexcept { } template<> void swap(funny::A(&)[3], funny::A(&)[3]) noexcept(false) { } } namespace ns1 { struct SwapThrow {}; void swap(SwapThrow&, SwapThrow&); void swap(SwapThrow(&)[3], SwapThrow(&)[3]) noexcept; } namespace ns2 { struct SwapThrow { SwapThrow() noexcept = default; SwapThrow(const SwapThrow&) noexcept(false); SwapThrow& operator=(const SwapThrow&) noexcept(false); }; } namespace ns3 { struct SwapNoThrow { SwapNoThrow() noexcept = default; SwapNoThrow(const SwapNoThrow&) noexcept(false); SwapNoThrow& operator =(const SwapNoThrow&) noexcept(false); }; void swap(SwapNoThrow&, SwapNoThrow&) noexcept; } namespace ns4 { struct SwapNoThrow {}; } namespace ns5 { struct SwapThrow { SwapThrow() noexcept = default; SwapThrow(SwapThrow&&) noexcept; SwapThrow& operator=(const SwapThrow&) noexcept(false); }; } namespace comps { struct CompareNoThrowCopyable { template bool operator()(const T&, const T&) const { return false; } }; struct CompareNonCopyable { CompareNonCopyable() = default; CompareNonCopyable(const CompareNonCopyable&) = delete; CompareNonCopyable& operator=(const CompareNonCopyable&) noexcept; template bool operator()(const T&, const T&) const { return false; } }; struct CompareThrowCopyable { CompareThrowCopyable() = default; CompareThrowCopyable(const CompareThrowCopyable&) noexcept(false); CompareThrowCopyable& operator=(const CompareThrowCopyable&); template bool operator()(const T&, const T&) const { return false; } }; } void test01() { using namespace __gnu_test; // Positive tests. static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(!noexcept(std::swap(std::declval(), std::declval())), ""); static_assert(test_property(true), ""); static_assert(!noexcept(std::swap(std::declval(), std::declval())), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property(true), ""); static_assert(test_property>(true), ""); static_assert(test_property[1]>(true), ""); static_assert(test_property[1][2]>(true), ""); static_assert(test_property>(true), ""); static_assert(test_property[1]>(true), ""); static_assert(test_property[1][2]>(true), ""); static_assert(test_property>(true), ""); static_assert(test_property[1]>(true), ""); static_assert(test_property[1][2]>(true), ""); static_assert(test_property>(true), ""); static_assert(test_property>(true), ""); static_assert(test_property>(true), ""); static_assert(test_property>(true), ""); static_assert(test_property>(true), ""); static_assert(test_property>(true), ""); static_assert(test_property>(true), ""); static_assert(test_property, comps::CompareNoThrowCopyable>>(true), ""); // Negative tests. static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(noexcept(std::swap(std::declval(), std::declval())), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property(false), ""); static_assert(test_property>(false), ""); static_assert(test_property>(false), ""); static_assert(test_property>(false), ""); static_assert(test_property>(true), ""); static_assert(test_property, comps::CompareNoThrowCopyable>>(true), ""); static_assert(test_property>(true), ""); static_assert(test_property, comps::CompareNonCopyable>>(false), ""); static_assert(test_property, comps::CompareThrowCopyable>>(false), ""); }