blob: c8ee2789df47ac3056dda05bfbf820f5bb962ae6 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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
Howard Hinnant3e519522010-05-11 19:42:16 +00006//
7//===----------------------------------------------------------------------===//
8
9// <cstring>
10
11#include <cstring>
12#include <type_traits>
13
Marshall Clowb766eb92018-12-18 19:07:30 +000014#include "test_macros.h"
15
Howard Hinnant3e519522010-05-11 19:42:16 +000016#ifndef NULL
17#error NULL not defined
18#endif
19
JF Bastien2df59c52019-02-04 20:31:13 +000020int main(int, char**)
Howard Hinnant3e519522010-05-11 19:42:16 +000021{
22 std::size_t s = 0;
23 void* vp = 0;
24 const void* vpc = 0;
25 char* cp = 0;
26 const char* cpc = 0;
Marshall Clowb766eb92018-12-18 19:07:30 +000027
28 ASSERT_SAME_TYPE(void*, decltype(std::memcpy(vp, vpc, s)));
29 ASSERT_SAME_TYPE(void*, decltype(std::memmove(vp, vpc, s)));
30 ASSERT_SAME_TYPE(char*, decltype(std::strcpy(cp, cpc)));
31 ASSERT_SAME_TYPE(char*, decltype(std::strncpy(cp, cpc, s)));
32 ASSERT_SAME_TYPE(char*, decltype(std::strcat(cp, cpc)));
33 ASSERT_SAME_TYPE(char*, decltype(std::strncat(cp, cpc, s)));
34 ASSERT_SAME_TYPE(int, decltype(std::memcmp(vpc, vpc, s)));
35 ASSERT_SAME_TYPE(int, decltype(std::strcmp(cpc, cpc)));
36 ASSERT_SAME_TYPE(int, decltype(std::strncmp(cpc, cpc, s)));
37 ASSERT_SAME_TYPE(int, decltype(std::strcoll(cpc, cpc)));
38 ASSERT_SAME_TYPE(std::size_t, decltype(std::strxfrm(cp, cpc, s)));
39 ASSERT_SAME_TYPE(void*, decltype(std::memchr(vp, 0, s)));
40 ASSERT_SAME_TYPE(char*, decltype(std::strchr(cp, 0)));
41 ASSERT_SAME_TYPE(std::size_t, decltype(std::strcspn(cpc, cpc)));
42 ASSERT_SAME_TYPE(char*, decltype(std::strpbrk(cp, cpc)));
43 ASSERT_SAME_TYPE(char*, decltype(std::strrchr(cp, 0)));
44 ASSERT_SAME_TYPE(std::size_t, decltype(std::strspn(cpc, cpc)));
45 ASSERT_SAME_TYPE(char*, decltype(std::strstr(cp, cpc)));
Ed Schoutene0cf3b92015-06-24 08:44:38 +000046#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
Marshall Clowb766eb92018-12-18 19:07:30 +000047 ASSERT_SAME_TYPE(char*, decltype(std::strtok(cp, cpc)));
Ed Schoutene0cf3b92015-06-24 08:44:38 +000048#endif
Marshall Clowb766eb92018-12-18 19:07:30 +000049 ASSERT_SAME_TYPE(void*, decltype(std::memset(vp, 0, s)));
50 ASSERT_SAME_TYPE(char*, decltype(std::strerror(0)));
51 ASSERT_SAME_TYPE(std::size_t, decltype(std::strlen(cpc)));
Richard Smith5fd17ab2016-02-10 00:59:02 +000052
53 // These tests fail on systems whose C library doesn't provide a correct overload
54 // set for strchr, strpbrk, strrchr, strstr, and memchr, unless the compiler is
55 // a suitably recent version of Clang.
56#if !defined(__APPLE__) || defined(_LIBCPP_PREFERRED_OVERLOAD)
Marshall Clowb766eb92018-12-18 19:07:30 +000057 ASSERT_SAME_TYPE(const void*, decltype(std::memchr(vpc, 0, s)));
58 ASSERT_SAME_TYPE(const char*, decltype(std::strchr(cpc, 0)));
59 ASSERT_SAME_TYPE(const char*, decltype(std::strpbrk(cpc, cpc)));
60 ASSERT_SAME_TYPE(const char*, decltype(std::strrchr(cpc, 0)));
61 ASSERT_SAME_TYPE(const char*, decltype(std::strstr(cpc, cpc)));
Richard Smith5fd17ab2016-02-10 00:59:02 +000062#endif
JF Bastien2df59c52019-02-04 20:31:13 +000063
64 return 0;
Howard Hinnant3e519522010-05-11 19:42:16 +000065}