| 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-options "-fchar8_t" } |
| 19 |
// { dg-do run } |
| 20 |
|
| 21 |
#include <algorithm> |
| 22 |
#include <testsuite_hooks.h> |
| 23 |
|
| 24 |
// Check that the memcmp optimization in std::lexicographical_compare |
| 25 |
// still works for mixed-type comparisons. |
| 26 |
|
| 27 |
void |
| 28 |
test01() |
| 29 |
{ |
| 30 |
unsigned char a = 0; |
| 31 |
char8_t b = 1; |
| 32 |
VERIFY( std::lexicographical_compare(&a, &a + 1, &b, &b + 1) ); |
| 33 |
VERIFY( ! std::lexicographical_compare(&b, &b + 1, &a, &a + 1) ); |
| 34 |
} |
| 35 |
|
| 36 |
void |
| 37 |
test02() |
| 38 |
{ |
| 39 |
// N.B. if char is signed this won't actually use the memcmp optimization. |
| 40 |
unsigned char a = 0; |
| 41 |
char b = 1; |
| 42 |
VERIFY( std::lexicographical_compare(&a, &a + 1, &b, &b + 1) ); |
| 43 |
VERIFY( ! std::lexicographical_compare(&b, &b + 1, &a, &a + 1) ); |
| 44 |
} |
| 45 |
|
| 46 |
void |
| 47 |
test03() |
| 48 |
{ |
| 49 |
// N.B. if char is signed this won't actually use the memcmp optimization. |
| 50 |
char a = 0; |
| 51 |
char8_t b = 1; |
| 52 |
VERIFY( std::lexicographical_compare(&a, &a + 1, &b, &b + 1) ); |
| 53 |
VERIFY( ! std::lexicographical_compare(&b, &b + 1, &a, &a + 1) ); |
| 54 |
} |
| 55 |
|
| 56 |
int main() |
| 57 |
{ |
| 58 |
test01(); |
| 59 |
test02(); |
| 60 |
test03(); |
| 61 |
} |