| 1 | // Copyright (C) 2019-2025 Free Software Foundation, Inc. |
| 2 | // |
| 3 | // This file is part of the GNU ISO C++ Library. This library is free |
| 4 | // software; you can redistribute it and/or modify it under the |
| 5 | // terms of the GNU General Public License as published by the |
| 6 | // Free Software Foundation; either version 3, or (at your option) |
| 7 | // any later version. |
| 8 | |
| 9 | // This library is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | |
| 14 | // You should have received a copy of the GNU General Public License along |
| 15 | // with this library; see the file COPYING3. If not see |
| 16 | // <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | // { dg-do compile { target c++20 } } |
| 19 | |
| 20 | #include <concepts> |
| 21 | |
| 22 | static_assert( !std::assignable_from<void, void> ); |
| 23 | static_assert( !std::assignable_from<void*, int*> ); |
| 24 | static_assert( std::assignable_from<void*&, int*> ); |
| 25 | static_assert( !std::assignable_from<void*&, const int*> ); |
| 26 | static_assert( std::assignable_from<const void*&, const int*> ); |
| 27 | static_assert( !std::assignable_from<char, char> ); |
| 28 | static_assert( std::assignable_from<char&, char> ); |
| 29 | static_assert( !std::assignable_from<float, float> ); |
| 30 | static_assert( std::assignable_from<float&, double> ); |
| 31 | static_assert( std::assignable_from<int*&, int*> ); |
| 32 | static_assert( std::assignable_from<int&, int&> ); |
| 33 | static_assert( std::assignable_from<int&, int&&> ); |
| 34 | static_assert( !std::assignable_from<int&&, int> ); |
| 35 | static_assert( !std::assignable_from<const int&, int> ); |
| 36 | static_assert( !std::assignable_from<const int&, int&> ); |
| 37 | static_assert( !std::assignable_from<const int&, const int> ); |
| 38 | static_assert( !std::assignable_from<const int&, const int&> ); |
| 39 | static_assert( !std::assignable_from<int(&)[], int(&)[]> ); |
| 40 | static_assert( !std::assignable_from<int(&)[], int> ); |
| 41 | static_assert( !std::assignable_from<int(&)[2], int(&)[2]> ); |
| 42 | static_assert( !std::assignable_from<int(), int()> ); |
| 43 | static_assert( !std::assignable_from<int(*)(), int(*)()> ); |
| 44 | static_assert( std::assignable_from<int(*&)(), int(*)()> ); |
| 45 | static_assert( std::assignable_from<int(*&)(), std::nullptr_t> ); |
| 46 | static_assert( std::assignable_from<int(*&)(), int(*)() noexcept> ); |
| 47 | static_assert( std::assignable_from<int(*&)(), int(&)() noexcept> ); |
| 48 | static_assert( !std::assignable_from<int(&)(), std::nullptr_t> ); |
| 49 | static_assert( !std::assignable_from<int(&)(), int(&)() noexcept> ); |
| 50 | |
| 51 | enum E { }; |
| 52 | static_assert( !std::assignable_from<E, E> ); |
| 53 | static_assert( std::assignable_from<E&, E> ); |
| 54 | static_assert( std::assignable_from<E&, E&> ); |
| 55 | static_assert( std::assignable_from<E&, const E&> ); |
| 56 | static_assert( !std::assignable_from<const E&, const E&> ); |
| 57 | enum class CE { }; |
| 58 | static_assert( !std::assignable_from<CE, CE> ); |
| 59 | static_assert( std::assignable_from<CE&, CE&> ); |
| 60 | static_assert( std::assignable_from<CE&, const CE&> ); |
| 61 | static_assert( !std::assignable_from<const CE&, const CE&> ); |
| 62 | struct A { }; |
| 63 | static_assert( !std::assignable_from<A, A> ); |
| 64 | static_assert( std::assignable_from<A&, A> ); |
| 65 | static_assert( !std::assignable_from<A, A&> ); |
| 66 | static_assert( std::assignable_from<A&, const A&> ); |
| 67 | union B { }; |
| 68 | static_assert( !std::assignable_from<B, B> ); |
| 69 | static_assert( std::assignable_from<B&, B> ); |
| 70 | static_assert( !std::assignable_from<B, B&> ); |
| 71 | static_assert( std::assignable_from<B&, const B&> ); |
| 72 | |
| 73 | struct C |
| 74 | { |
| 75 | C(int) { } |
| 76 | C& operator=(const C&) { return *this; } |
| 77 | C& operator=(int) { return *this; } |
| 78 | void operator=(void*) { } |
| 79 | }; |
| 80 | static_assert( std::assignable_from<C&, C> ); |
| 81 | static_assert( std::assignable_from<C&, const C&> ); |
| 82 | static_assert( std::assignable_from<C&, int> ); |
| 83 | static_assert( !std::assignable_from<C&, void*> ); |
| 84 | static_assert( !std::assignable_from<C&, std::nullptr_t> ); |