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 //===----------------------------------------------------------------------===//
14 #include "test_macros.h"
17 #error NULL not defined
20 int main(int, char**) {
21 // Functions we get directly from the C library (just check the signature)
28 ASSERT_SAME_TYPE(void*, decltype(memcpy(vp
, vpc
, s
)));
29 ASSERT_SAME_TYPE(void*, decltype(memmove(vp
, vpc
, s
)));
30 ASSERT_SAME_TYPE(char*, decltype(strcpy(cp
, cpc
)));
31 ASSERT_SAME_TYPE(char*, decltype(strncpy(cp
, cpc
, s
)));
32 ASSERT_SAME_TYPE(char*, decltype(strcat(cp
, cpc
)));
33 ASSERT_SAME_TYPE(char*, decltype(strncat(cp
, cpc
, s
)));
34 ASSERT_SAME_TYPE(int, decltype(memcmp(vpc
, vpc
, s
)));
35 ASSERT_SAME_TYPE(int, decltype(strcmp(cpc
, cpc
)));
36 ASSERT_SAME_TYPE(int, decltype(strncmp(cpc
, cpc
, s
)));
37 ASSERT_SAME_TYPE(int, decltype(strcoll(cpc
, cpc
)));
38 ASSERT_SAME_TYPE(size_t, decltype(strxfrm(cp
, cpc
, s
)));
39 ASSERT_SAME_TYPE(size_t, decltype(strcspn(cpc
, cpc
)));
40 ASSERT_SAME_TYPE(size_t, decltype(strspn(cpc
, cpc
)));
41 ASSERT_SAME_TYPE(char*, decltype(strtok(cp
, cpc
)));
42 ASSERT_SAME_TYPE(void*, decltype(memset(vp
, 0, s
)));
43 ASSERT_SAME_TYPE(char*, decltype(strerror(0)));
44 ASSERT_SAME_TYPE(size_t, decltype(strlen(cpc
)));
47 // Functions we (may) reimplement
49 // const char* strchr(const char*, int)
50 char storage
[] = "hello world";
51 const char* s
= storage
;
52 ASSERT_SAME_TYPE(const char*, decltype(strchr(s
, 'l')));
53 const char* res
= strchr(s
, 'l');
57 // char* strchr(char*, int)
58 char storage
[] = "hello world";
60 ASSERT_SAME_TYPE(char*, decltype(strchr(s
, 'l')));
61 char* res
= strchr(s
, 'l');
66 // const char* strpbrk(const char*, const char*)
67 char storage
[] = "hello world";
68 const char* s
= storage
;
69 ASSERT_SAME_TYPE(const char*, decltype(strpbrk(s
, "el")));
70 const char* res
= strpbrk(s
, "el");
74 // char* strpbrk(char*, const char*)
75 char storage
[] = "hello world";
77 ASSERT_SAME_TYPE(char*, decltype(strpbrk(s
, "el")));
78 char* res
= strpbrk(s
, "el");
83 // const char* strrchr(const char*, int)
84 char storage
[] = "hello world";
85 const char* s
= storage
;
86 ASSERT_SAME_TYPE(const char*, decltype(strrchr(s
, 'l')));
87 const char* res
= strrchr(s
, 'l');
91 // char* strrchr(char*, int)
92 char storage
[] = "hello world";
94 ASSERT_SAME_TYPE(char*, decltype(strrchr(s
, 'l')));
95 char* res
= strrchr(s
, 'l');
100 // const void* memchr(const void*, int, size_t)
101 char storage
[] = "hello world";
103 const void* s
= storage
;
104 ASSERT_SAME_TYPE(const void*, decltype(memchr(s
, 'l', count
)));
105 const void* res
= memchr(s
, 'l', count
);
106 assert(res
== &storage
[2]);
109 // void* memchr(void*, int, size_t)
110 char storage
[] = "hello world";
113 ASSERT_SAME_TYPE(void*, decltype(memchr(s
, 'l', count
)));
114 void* res
= memchr(s
, 'l', count
);
115 assert(res
== &storage
[2]);
119 // const char* strstr(const char*, const char*)
120 char storage
[] = "hello world";
121 const char* s
= storage
;
122 ASSERT_SAME_TYPE(const char*, decltype(strstr(s
, "wor")));
123 const char* res
= strstr(s
, "wor");
124 assert(res
== &storage
[6]);
127 // char* strstr(char*, const char*)
128 char storage
[] = "hello world";
130 ASSERT_SAME_TYPE(char*, decltype(strstr(s
, "wor")));
131 char* res
= strstr(s
, "wor");
132 assert(res
== &storage
[6]);