string_h.pass.cpp
3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string.h>
#include <string.h>
#include <type_traits>
#include "test_macros.h"
#ifndef NULL
#error NULL not defined
#endif
int main(int, char**)
{
size_t s = 0;
void* vp = 0;
const void* vpc = 0;
char* cp = 0;
const char* cpc = 0;
static_assert((std::is_same<decltype(memcpy(vp, vpc, s)), void*>::value), "");
static_assert((std::is_same<decltype(memmove(vp, vpc, s)), void*>::value), "");
static_assert((std::is_same<decltype(strcpy(cp, cpc)), char*>::value), "");
static_assert((std::is_same<decltype(strncpy(cp, cpc, s)), char*>::value), "");
static_assert((std::is_same<decltype(strcat(cp, cpc)), char*>::value), "");
static_assert((std::is_same<decltype(strncat(cp, cpc, s)), char*>::value), "");
static_assert((std::is_same<decltype(memcmp(vpc, vpc, s)), int>::value), "");
static_assert((std::is_same<decltype(strcmp(cpc, cpc)), int>::value), "");
static_assert((std::is_same<decltype(strncmp(cpc, cpc, s)), int>::value), "");
static_assert((std::is_same<decltype(strcoll(cpc, cpc)), int>::value), "");
static_assert((std::is_same<decltype(strxfrm(cp, cpc, s)), size_t>::value), "");
static_assert((std::is_same<decltype(memchr(vp, 0, s)), void*>::value), "");
static_assert((std::is_same<decltype(strchr(cp, 0)), char*>::value), "");
static_assert((std::is_same<decltype(strcspn(cpc, cpc)), size_t>::value), "");
static_assert((std::is_same<decltype(strpbrk(cp, cpc)), char*>::value), "");
static_assert((std::is_same<decltype(strrchr(cp, 0)), char*>::value), "");
static_assert((std::is_same<decltype(strspn(cpc, cpc)), size_t>::value), "");
static_assert((std::is_same<decltype(strstr(cp, cpc)), char*>::value), "");
#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
static_assert((std::is_same<decltype(strtok(cp, cpc)), char*>::value), "");
#endif
static_assert((std::is_same<decltype(memset(vp, 0, s)), void*>::value), "");
static_assert((std::is_same<decltype(strerror(0)), char*>::value), "");
static_assert((std::is_same<decltype(strlen(cpc)), size_t>::value), "");
// These tests fail on systems whose C library doesn't provide a correct overload
// set for strchr, strpbrk, strrchr, strstr, and memchr, unless the compiler is
// a suitably recent version of Clang.
#if !defined(__APPLE__) || defined(_LIBCPP_PREFERRED_OVERLOAD)
static_assert((std::is_same<decltype(strchr(cpc, 0)), const char*>::value), "");
static_assert((std::is_same<decltype(strpbrk(cpc, cpc)), const char*>::value), "");
static_assert((std::is_same<decltype(strrchr(cpc, 0)), const char*>::value), "");
static_assert((std::is_same<decltype(strstr(cpc, cpc)), const char*>::value), "");
static_assert((std::is_same<decltype(memchr(vpc, 0, s)), const void*>::value), "");
#endif
return 0;
}