| 1 |
// { dg-do compile { target c++20 } } |
| 2 |
// { dg-add-options no_pch } |
| 3 |
|
| 4 |
// Copyright (C) 2017-2025 Free Software Foundation, Inc. |
| 5 |
// |
| 6 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 7 |
// software; you can redistribute it and/or modify it under the |
| 8 |
// terms of the GNU General Public License as published by the |
| 9 |
// Free Software Foundation; either version 3, or (at your option) |
| 10 |
// any later version. |
| 11 |
|
| 12 |
// This library is distributed in the hope that it will be useful, |
| 13 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
// GNU General Public License for more details. |
| 16 |
|
| 17 |
// You should have received a copy of the GNU General Public License along |
| 18 |
// with this library; see the file COPYING3. If not see |
| 19 |
// <http://www.gnu.org/licenses/>. |
| 20 |
|
| 21 |
#include <string> |
| 22 |
|
| 23 |
template<typename CT> |
| 24 |
constexpr bool |
| 25 |
test_move() |
| 26 |
{ |
| 27 |
using char_type = typename CT::char_type; |
| 28 |
|
| 29 |
// Overlapping strings |
| 30 |
char_type s1[3] = {1, 2, 3}; |
| 31 |
CT::move(s1+1, s1, 2); |
| 32 |
if (s1[0] != char_type{1} || s1[1] != char_type{1} || s1[2] != char_type{2}) |
| 33 |
throw 1; |
| 34 |
CT::move(s1, s1+1, 2); |
| 35 |
if (s1[0] != char_type{1} || s1[1] != char_type{2} || s1[2] != char_type{2}) |
| 36 |
throw 2; |
| 37 |
|
| 38 |
// Disjoint strings |
| 39 |
char_type why_is_six_scared_of_seven[] = {4, 5, 6}; |
| 40 |
char_type because789[] = {7, 8, 9}; |
| 41 |
CT::move(why_is_six_scared_of_seven, because789, 3); |
| 42 |
if (why_is_six_scared_of_seven[0] != char_type{7} |
| 43 |
|| why_is_six_scared_of_seven[1] != char_type{8} |
| 44 |
|| why_is_six_scared_of_seven[2] != char_type{9}) |
| 45 |
throw 3; |
| 46 |
|
| 47 |
return true; |
| 48 |
} |
| 49 |
|
| 50 |
#ifndef __cpp_lib_constexpr_string |
| 51 |
# error Feature-test macro for constexpr char_traits is missing |
| 52 |
#elif __cpp_lib_constexpr_string < 201811 |
| 53 |
# error Feature-test macro for constexpr char_traits has the wrong value |
| 54 |
#endif |
| 55 |
|
| 56 |
// We also provide this non-standard macro for P0426R1 and P1032R1. |
| 57 |
#ifndef __cpp_lib_constexpr_char_traits |
| 58 |
# error Feature-test macro for constexpr char_traits is missing |
| 59 |
#elif __cpp_lib_constexpr_char_traits != 201811 |
| 60 |
# error Feature-test macro for constexpr char_traits has the wrong value |
| 61 |
#endif |
| 62 |
|
| 63 |
static_assert( test_move<std::char_traits<char>>() ); |
| 64 |
static_assert( test_move<std::char_traits<wchar_t>>() ); |
| 65 |
#ifdef _GLIBCXX_USE_CHAR8_T |
| 66 |
static_assert( test_move<std::char_traits<char8_t>>() ); |
| 67 |
#endif |
| 68 |
static_assert( test_move<std::char_traits<char16_t>>() ); |
| 69 |
static_assert( test_move<std::char_traits<char32_t>>() ); |
| 70 |
|
| 71 |
struct C { unsigned char c; }; |
| 72 |
constexpr bool operator==(const C& c1, const C& c2) { return c1.c == c2.c; } |
| 73 |
constexpr bool operator<(const C& c1, const C& c2) { return c1.c < c2.c; } |
| 74 |
static_assert( test_move<std::char_traits<C>>() ); |