]>
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 } }
3 // Copyright (C) 2017-2022 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
26 using char_type
= typename
CT::char_type
;
28 const char_type s2
[2] = {1, 0};
29 CT::assign(s1
[0], s2
[0]);
30 return s1
[0] == char_type
{1};
37 using char_type
= typename
CT::char_type
;
38 const char_type s1
[3] = {1, 2, 3};
39 const char_type s2
[3] = {1, 2, 3};
40 if (CT::compare(s1
, s2
, 3) != 0)
42 if (CT::compare(s2
, s1
, 3) != 0)
44 if (CT::compare(s1
+1, s2
, 2) <= 0)
53 using char_type
= typename
CT::char_type
;
54 const char_type s1
[4] = {1, 2, 3, 0};
55 if (CT::length(s1
) != 3)
57 if (CT::length(s1
+1) != 2)
66 using char_type
= typename
CT::char_type
;
67 const char_type s1
[3] = {1, 2, 3};
68 if (CT::find(s1
, 3, char_type
{2}) != s1
+1)
70 if (CT::find(s1
, 3, char_type
{4}) != nullptr)
75 #ifndef __cpp_lib_constexpr_string
76 # error Feature-test macro for constexpr char_traits is missing
77 #elif __cpp_lib_constexpr_string < (__cplusplus == 201703 ? 201611 : 201811)
78 # error Feature-test macro for constexpr char_traits has the wrong value
81 // We also provide this non-standard macro for P0426R1 (and P1032R1 in C++20).
82 #ifndef __cpp_lib_constexpr_char_traits
83 # error Feature-test macro for constexpr char_traits is missing
84 #elif __cpp_lib_constexpr_char_traits != (__cplusplus == 201703 ? 201611 : 201811)
85 # error Feature-test macro for constexpr char_traits has the wrong value
88 static_assert( test_assign
<std::char_traits
<char>>() );
89 static_assert( test_compare
<std::char_traits
<char>>() );
90 static_assert( test_length
<std::char_traits
<char>>() );
91 static_assert( test_find
<std::char_traits
<char>>() );
92 static_assert( test_assign
<std::char_traits
<wchar_t>>() );
93 static_assert( test_compare
<std::char_traits
<wchar_t>>() );
94 static_assert( test_length
<std::char_traits
<wchar_t>>() );
95 static_assert( test_find
<std::char_traits
<wchar_t>>() );
96 #ifdef _GLIBCXX_USE_CHAR8_T
97 static_assert( test_assign
<std::char_traits
<char8_t
>>() );
98 static_assert( test_compare
<std::char_traits
<char8_t
>>() );
99 static_assert( test_length
<std::char_traits
<char8_t
>>() );
100 static_assert( test_find
<std::char_traits
<char8_t
>>() );
102 static_assert( test_assign
<std::char_traits
<char16_t
>>() );
103 static_assert( test_compare
<std::char_traits
<char16_t
>>() );
104 static_assert( test_length
<std::char_traits
<char16_t
>>() );
105 static_assert( test_find
<std::char_traits
<char16_t
>>() );
106 static_assert( test_assign
<std::char_traits
<char32_t
>>() );
107 static_assert( test_compare
<std::char_traits
<char32_t
>>() );
108 static_assert( test_length
<std::char_traits
<char32_t
>>() );
109 static_assert( test_find
<std::char_traits
<char32_t
>>() );
111 struct C
{ unsigned char c
; };
112 constexpr bool operator==(const C
& c1
, const C
& c2
) { return c1
.c
== c2
.c
; }
113 constexpr bool operator<(const C
& c1
, const C
& c2
) { return c1
.c
< c2
.c
; }
114 static_assert( test_assign
<std::char_traits
<C
>>() );
115 static_assert( test_compare
<std::char_traits
<C
>>() );
116 static_assert( test_length
<std::char_traits
<C
>>() );
117 static_assert( test_find
<std::char_traits
<C
>>() );