| 1 | // Copyright (C) 2020-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 run { target c++11 } } |
| 19 | |
| 20 | #include <algorithm> |
| 21 | #include <testsuite_hooks.h> |
| 22 | |
| 23 | void |
| 24 | test01() |
| 25 | { |
| 26 | volatile int i[2] = { 1, 2 }; |
| 27 | volatile int j[2] = { 0, 0 }; |
| 28 | int k[2] = { 0, 0 }; |
| 29 | |
| 30 | std::move(i, i+2, j); |
| 31 | VERIFY( j[0] == 1 && j[1] == 2 ); |
| 32 | std::move(i, i+2, k); |
| 33 | VERIFY( k[0] == 1 && k[1] == 2 ); |
| 34 | std::move(k+1, k+2, i); |
| 35 | VERIFY( i[0] == 2 ); |
| 36 | |
| 37 | const volatile int* cj = j; |
| 38 | std::move(cj, cj+2, i); |
| 39 | VERIFY( i[0] == 1 && i[1] == 2 ); |
| 40 | std::move(cj+1, cj+2, k); |
| 41 | VERIFY( k[0] == 2 ); |
| 42 | const int* ck = k; |
| 43 | std::move(ck, ck+2, i); |
| 44 | VERIFY( i[0] == 2 && i[1] == 2 ); |
| 45 | } |
| 46 | |
| 47 | void |
| 48 | test02() |
| 49 | { |
| 50 | #if __cplusplus > 201703L |
| 51 | volatile int i[2] = { 1, 2 }; |
| 52 | volatile int j[2] = { 0, 0 }; |
| 53 | int k[2] = { 0, 0 }; |
| 54 | |
| 55 | std::ranges::move(i, i+2, j); |
| 56 | VERIFY( j[0] == 1 && j[1] == 2 ); |
| 57 | std::ranges::move(i, i+2, k); |
| 58 | VERIFY( k[0] == 1 && k[1] == 2 ); |
| 59 | std::ranges::move(k+1, k+2, i); |
| 60 | VERIFY( i[0] == 2 ); |
| 61 | |
| 62 | const volatile int* cj = j; |
| 63 | std::ranges::move(cj, cj+2, i); |
| 64 | VERIFY( i[0] == 1 && i[1] == 2 ); |
| 65 | std::ranges::move(cj+1, cj+2, k); |
| 66 | VERIFY( k[0] == 2 ); |
| 67 | const int* ck = k; |
| 68 | std::ranges::move(ck, ck+2, i); |
| 69 | VERIFY( i[0] == 2 && i[1] == 2 ); |
| 70 | #endif |
| 71 | } |
| 72 | |
| 73 | int |
| 74 | main() |
| 75 | { |
| 76 | test01(); |
| 77 | test02(); |
| 78 | } |