]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/char_traits/requirements/constexpr_functions_c++17.cc
1 // { dg-do compile { target c++17 } }
2 // { dg-add-options no_pch }
4 // Copyright (C) 2017-2024 Free Software Foundation, Inc.
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)
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.
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/>.
27 using char_type
= typename
CT::char_type
;
29 const char_type s2
[2] = {1, 0};
30 CT::assign(s1
[0], s2
[0]);
31 return s1
[0] == char_type
{1};
38 using char_type
= typename
CT::char_type
;
39 const char_type s1
[3] = {1, 2, 3};
40 const char_type s2
[3] = {1, 2, 3};
41 if (CT::compare(s1
, s2
, 3) != 0)
43 if (CT::compare(s2
, s1
, 3) != 0)
45 if (CT::compare(s1
+1, s2
, 2) <= 0)
54 using char_type
= typename
CT::char_type
;
55 const char_type s1
[4] = {1, 2, 3, 0};
56 if (CT::length(s1
) != 3)
58 if (CT::length(s1
+1) != 2)
67 using char_type
= typename
CT::char_type
;
68 const char_type s1
[3] = {1, 2, 3};
69 if (CT::find(s1
, 3, char_type
{2}) != s1
+1)
71 if (CT::find(s1
, 3, char_type
{4}) != nullptr)
76 #ifndef __cpp_lib_constexpr_string
77 # error Feature-test macro for constexpr char_traits is missing
78 #elif __cpp_lib_constexpr_string < (__cplusplus == 201703 ? 201611 : 201811)
79 # error Feature-test macro for constexpr char_traits has the wrong value
82 // We also provide this non-standard macro for P0426R1 (and P1032R1 in C++20).
83 #ifndef __cpp_lib_constexpr_char_traits
84 # error Feature-test macro for constexpr char_traits is missing
85 #elif __cpp_lib_constexpr_char_traits != (__cplusplus == 201703 ? 201611 : 201811)
86 # error Feature-test macro for constexpr char_traits has the wrong value
89 static_assert( test_assign
<std::char_traits
<char>>() );
90 static_assert( test_compare
<std::char_traits
<char>>() );
91 static_assert( test_length
<std::char_traits
<char>>() );
92 static_assert( test_find
<std::char_traits
<char>>() );
93 static_assert( test_assign
<std::char_traits
<wchar_t>>() );
94 static_assert( test_compare
<std::char_traits
<wchar_t>>() );
95 static_assert( test_length
<std::char_traits
<wchar_t>>() );
96 static_assert( test_find
<std::char_traits
<wchar_t>>() );
97 #ifdef _GLIBCXX_USE_CHAR8_T
98 static_assert( test_assign
<std::char_traits
<char8_t
>>() );
99 static_assert( test_compare
<std::char_traits
<char8_t
>>() );
100 static_assert( test_length
<std::char_traits
<char8_t
>>() );
101 static_assert( test_find
<std::char_traits
<char8_t
>>() );
103 static_assert( test_assign
<std::char_traits
<char16_t
>>() );
104 static_assert( test_compare
<std::char_traits
<char16_t
>>() );
105 static_assert( test_length
<std::char_traits
<char16_t
>>() );
106 static_assert( test_find
<std::char_traits
<char16_t
>>() );
107 static_assert( test_assign
<std::char_traits
<char32_t
>>() );
108 static_assert( test_compare
<std::char_traits
<char32_t
>>() );
109 static_assert( test_length
<std::char_traits
<char32_t
>>() );
110 static_assert( test_find
<std::char_traits
<char32_t
>>() );
112 struct C
{ unsigned char c
; };
113 constexpr bool operator==(const C
& c1
, const C
& c2
) { return c1
.c
== c2
.c
; }
114 constexpr bool operator<(const C
& c1
, const C
& c2
) { return c1
.c
< c2
.c
; }
115 static_assert( test_assign
<std::char_traits
<C
>>() );
116 static_assert( test_compare
<std::char_traits
<C
>>() );
117 static_assert( test_length
<std::char_traits
<C
>>() );
118 static_assert( test_find
<std::char_traits
<C
>>() );