1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // test <stdlib.h>
11
12 #include <stdlib.h>
13 #include <type_traits>
14
15 #ifndef EXIT_FAILURE
16 #error EXIT_FAILURE not defined
17 #endif
18
19 #ifndef EXIT_SUCCESS
20 #error EXIT_SUCCESS not defined
21 #endif
22
23 #ifndef MB_CUR_MAX
24 #error MB_CUR_MAX not defined
25 #endif
26
27 #ifndef NULL
28 #error NULL not defined
29 #endif
30
31 #ifndef RAND_MAX
32 #error RAND_MAX not defined
33 #endif
34
main()35 int main()
36 {
37 size_t s = 0; ((void)s);
38 div_t d; ((void)d);
39 ldiv_t ld; ((void)ld);
40 lldiv_t lld; ((void)lld);
41 char** endptr = 0;
42 static_assert((std::is_same<decltype(atof("")), double>::value), "");
43 static_assert((std::is_same<decltype(atoi("")), int>::value), "");
44 static_assert((std::is_same<decltype(atol("")), long>::value), "");
45 static_assert((std::is_same<decltype(atoll("")), long long>::value), "");
46 static_assert((std::is_same<decltype(getenv("")), char*>::value), "");
47 static_assert((std::is_same<decltype(strtod("", endptr)), double>::value), "");
48 static_assert((std::is_same<decltype(strtof("", endptr)), float>::value), "");
49 static_assert((std::is_same<decltype(strtold("", endptr)), long double>::value), "");
50 static_assert((std::is_same<decltype(strtol("", endptr,0)), long>::value), "");
51 static_assert((std::is_same<decltype(strtoll("", endptr,0)), long long>::value), "");
52 static_assert((std::is_same<decltype(strtoul("", endptr,0)), unsigned long>::value), "");
53 static_assert((std::is_same<decltype(strtoull("", endptr,0)), unsigned long long>::value), "");
54 static_assert((std::is_same<decltype(rand()), int>::value), "");
55 static_assert((std::is_same<decltype(srand(0)), void>::value), "");
56 static_assert((std::is_same<decltype(calloc(0,0)), void*>::value), "");
57 static_assert((std::is_same<decltype(free(0)), void>::value), "");
58 static_assert((std::is_same<decltype(malloc(0)), void*>::value), "");
59 static_assert((std::is_same<decltype(realloc(0,0)), void*>::value), "");
60 static_assert((std::is_same<decltype(abort()), void>::value), "");
61 static_assert((std::is_same<decltype(atexit(0)), int>::value), "");
62 static_assert((std::is_same<decltype(exit(0)), void>::value), "");
63 static_assert((std::is_same<decltype(_Exit(0)), void>::value), "");
64 static_assert((std::is_same<decltype(getenv("")), char*>::value), "");
65 static_assert((std::is_same<decltype(system("")), int>::value), "");
66 static_assert((std::is_same<decltype(bsearch(0,0,0,0,0)), void*>::value), "");
67 static_assert((std::is_same<decltype(qsort(0,0,0,0)), void>::value), "");
68 static_assert((std::is_same<decltype(abs(0)), int>::value), "");
69 static_assert((std::is_same<decltype(labs((long)0)), long>::value), "");
70 static_assert((std::is_same<decltype(llabs((long long)0)), long long>::value), "");
71 static_assert((std::is_same<decltype(div(0,0)), div_t>::value), "");
72 static_assert((std::is_same<decltype(ldiv(0L,0L)), ldiv_t>::value), "");
73 static_assert((std::is_same<decltype(lldiv(0LL,0LL)), lldiv_t>::value), "");
74 wchar_t* pw = 0;
75 const wchar_t* pwc = 0;
76 char* pc = 0;
77 #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
78 static_assert((std::is_same<decltype(mblen("",0)), int>::value), "");
79 static_assert((std::is_same<decltype(mbtowc(pw,"",0)), int>::value), "");
80 static_assert((std::is_same<decltype(wctomb(pc,L' ')), int>::value), "");
81 #endif
82 static_assert((std::is_same<decltype(mbstowcs(pw,"",0)), size_t>::value), "");
83 static_assert((std::is_same<decltype(wcstombs(pc,pwc,0)), size_t>::value), "");
84 }
85