| 1 | // { dg-do compile { target c++20 } } |
| 2 | // { dg-add-options no_pch } |
| 3 | |
| 4 | #include <type_traits> |
| 5 | |
| 6 | #ifndef __cpp_lib_is_pointer_interconvertible |
| 7 | # error "Feature test macro for is_pointer_interconvertible is missing in <type_traits>" |
| 8 | #elif __cpp_lib_is_pointer_interconvertible < 201907L |
| 9 | # error "Feature test macro for is_pointer_interconvertible has wrong value in <type_traits>" |
| 10 | #endif |
| 11 | |
| 12 | static_assert( std::is_pointer_interconvertible_base_of<void, void>::value |
| 13 | == std::is_pointer_interconvertible_base_of_v<void, void> ); |
| 14 | |
| 15 | struct B { }; |
| 16 | |
| 17 | static_assert( std::is_pointer_interconvertible_base_of<B, B>::value |
| 18 | == std::is_pointer_interconvertible_base_of_v<B, B> ); |
| 19 | |
| 20 | static_assert( std::is_pointer_interconvertible_base_of_v<B, B> ); |
| 21 | static_assert( std::is_pointer_interconvertible_base_of_v<B, const B> ); |
| 22 | static_assert( std::is_pointer_interconvertible_base_of_v<const B, B> ); |
| 23 | static_assert( std::is_pointer_interconvertible_base_of_v<const B, const B> ); |
| 24 | |
| 25 | struct D : B { int i; }; |
| 26 | |
| 27 | static_assert( std::is_pointer_interconvertible_base_of_v<D, D> ); |
| 28 | |
| 29 | static_assert( std::is_pointer_interconvertible_base_of_v<B, D> ); |
| 30 | static_assert( std::is_pointer_interconvertible_base_of_v<const B, D> ); |
| 31 | static_assert( std::is_pointer_interconvertible_base_of_v<B, const D> ); |
| 32 | static_assert( std::is_pointer_interconvertible_base_of_v<const B, const D> ); |
| 33 | |
| 34 | static_assert( ! std::is_pointer_interconvertible_base_of_v<D, B> ); |
| 35 | |
| 36 | struct E : D { }; |
| 37 | // E is not standard-layout |
| 38 | static_assert( ! std::is_pointer_interconvertible_base_of_v<E, B> ); |
| 39 | |
| 40 | struct D1 : B { }; |
| 41 | struct D2 : B { }; |
| 42 | struct D3 : D1, D2 { }; |
| 43 | // B is ambiguously derived |
| 44 | static_assert( ! std::is_pointer_interconvertible_base_of_v<B, D3> ); |
| 45 | |
| 46 | union U; |
| 47 | static_assert( ! std::is_pointer_interconvertible_base_of_v<U, U> ); |
| 48 | static_assert( ! std::is_pointer_interconvertible_base_of_v<U, D> ); |
| 49 | |
| 50 | struct I; // incomplete |
| 51 | static_assert( std::is_pointer_interconvertible_base_of_v<I, I> ); |
| 52 | static_assert( std::is_pointer_interconvertible_base_of_v<I, const I> ); |