| 1 |
// { dg-do compile { target c++20 } } |
| 2 |
|
| 3 |
#include <utility> |
| 4 |
|
| 5 |
// This is a GCC extension. std::exchange is not required to be noexcept. |
| 6 |
|
| 7 |
static_assert( noexcept( std::exchange(std::declval<int&>(), 1) ) ); |
| 8 |
|
| 9 |
struct X |
| 10 |
{ |
| 11 |
X(const X&); |
| 12 |
X(X&&) noexcept; |
| 13 |
X& operator=(const X&); |
| 14 |
X& operator=(X&&) noexcept; |
| 15 |
X& operator=(int); |
| 16 |
}; |
| 17 |
|
| 18 |
extern X x, x2; |
| 19 |
static_assert( noexcept( std::exchange(x, std::move(x2)) ) ); |
| 20 |
static_assert( ! noexcept( std::exchange(x, 1) ) ); |
| 21 |
|
| 22 |
struct Y |
| 23 |
{ |
| 24 |
Y(Y&&) noexcept; |
| 25 |
Y& operator=(Y&&); |
| 26 |
}; |
| 27 |
|
| 28 |
extern Y y, y2; |
| 29 |
static_assert( ! noexcept( std::exchange(y, std::move(y2)) ) ); |
| 30 |
|
| 31 |
struct Z |
| 32 |
{ |
| 33 |
Z(Z&&)noexcept; |
| 34 |
Z& operator=(Z&&) ; |
| 35 |
}; |
| 36 |
|
| 37 |
extern Z z, z2; |
| 38 |
static_assert( ! noexcept( std::exchange(z, std::move(z2)) ) ); |