1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 #include <type_traits>
15 #include "test_macros.h"
18 # error NULL not defined
21 int main(int, char**) {
22 // Functions we get directly from the C library (just check the signature)
29 ASSERT_SAME_TYPE(void*, decltype(std::memcpy(vp
, vpc
, s
)));
30 ASSERT_SAME_TYPE(void*, decltype(std::memmove(vp
, vpc
, s
)));
31 ASSERT_SAME_TYPE(char*, decltype(std::strcpy(cp
, cpc
)));
32 ASSERT_SAME_TYPE(char*, decltype(std::strncpy(cp
, cpc
, s
)));
33 ASSERT_SAME_TYPE(char*, decltype(std::strcat(cp
, cpc
)));
34 ASSERT_SAME_TYPE(char*, decltype(std::strncat(cp
, cpc
, s
)));
35 ASSERT_SAME_TYPE(int, decltype(std::memcmp(vpc
, vpc
, s
)));
36 ASSERT_SAME_TYPE(int, decltype(std::strcmp(cpc
, cpc
)));
37 ASSERT_SAME_TYPE(int, decltype(std::strncmp(cpc
, cpc
, s
)));
38 ASSERT_SAME_TYPE(int, decltype(std::strcoll(cpc
, cpc
)));
39 ASSERT_SAME_TYPE(std::size_t, decltype(std::strxfrm(cp
, cpc
, s
)));
40 ASSERT_SAME_TYPE(std::size_t, decltype(std::strcspn(cpc
, cpc
)));
41 ASSERT_SAME_TYPE(std::size_t, decltype(std::strspn(cpc
, cpc
)));
42 ASSERT_SAME_TYPE(char*, decltype(std::strtok(cp
, cpc
)));
43 ASSERT_SAME_TYPE(void*, decltype(std::memset(vp
, 0, s
)));
44 ASSERT_SAME_TYPE(char*, decltype(std::strerror(0)));
45 ASSERT_SAME_TYPE(std::size_t, decltype(std::strlen(cpc
)));
48 // Functions we (may) reimplement
50 // const char* strchr(const char*, int)
51 char storage
[] = "hello world";
52 const char* s
= storage
;
53 ASSERT_SAME_TYPE(const char*, decltype(std::strchr(s
, 'l')));
54 const char* res
= std::strchr(s
, 'l');
58 // char* strchr(char*, int)
59 char storage
[] = "hello world";
61 ASSERT_SAME_TYPE(char*, decltype(std::strchr(s
, 'l')));
62 char* res
= std::strchr(s
, 'l');
67 // const char* strpbrk(const char*, const char*)
68 char storage
[] = "hello world";
69 const char* s
= storage
;
70 ASSERT_SAME_TYPE(const char*, decltype(std::strpbrk(s
, "el")));
71 const char* res
= std::strpbrk(s
, "el");
75 // char* strpbrk(char*, const char*)
76 char storage
[] = "hello world";
78 ASSERT_SAME_TYPE(char*, decltype(std::strpbrk(s
, "el")));
79 char* res
= std::strpbrk(s
, "el");
84 // const char* strrchr(const char*, int)
85 char storage
[] = "hello world";
86 const char* s
= storage
;
87 ASSERT_SAME_TYPE(const char*, decltype(std::strrchr(s
, 'l')));
88 const char* res
= std::strrchr(s
, 'l');
92 // char* strrchr(char*, int)
93 char storage
[] = "hello world";
95 ASSERT_SAME_TYPE(char*, decltype(std::strrchr(s
, 'l')));
96 char* res
= std::strrchr(s
, 'l');
101 // const void* memchr(const void*, int, size_t)
102 char storage
[] = "hello world";
103 std::size_t count
= 11;
104 const void* s
= storage
;
105 ASSERT_SAME_TYPE(const void*, decltype(std::memchr(s
, 'l', count
)));
106 const void* res
= std::memchr(s
, 'l', count
);
107 assert(res
== &storage
[2]);
110 // void* memchr(void*, int, size_t)
111 char storage
[] = "hello world";
112 std::size_t count
= 11;
114 ASSERT_SAME_TYPE(void*, decltype(std::memchr(s
, 'l', count
)));
115 void* res
= std::memchr(s
, 'l', count
);
116 assert(res
== &storage
[2]);
120 // const char* strstr(const char*, const char*)
121 char storage
[] = "hello world";
122 const char* s
= storage
;
123 ASSERT_SAME_TYPE(const char*, decltype(std::strstr(s
, "wor")));
124 const char* res
= std::strstr(s
, "wor");
125 assert(res
== &storage
[6]);
128 // char* strstr(char*, const char*)
129 char storage
[] = "hello world";
131 ASSERT_SAME_TYPE(char*, decltype(std::strstr(s
, "wor")));
132 char* res
= std::strstr(s
, "wor");
133 assert(res
== &storage
[6]);