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 #include "test_macros.h"
16 
17 // As of 1/10/2015 clang emits a -Wnonnull warnings even if the warning occurs
18 // in an unevaluated context. For this reason we manually suppress the warning.
19 #if defined(__clang__)
20 #pragma clang diagnostic ignored "-Wnonnull"
21 #endif
22 
23 #ifdef abs
24 #error abs is defined
25 #endif
26 
27 #ifdef labs
28 #error labs is defined
29 #endif
30 
31 #ifdef llabs
32 #error llabs is defined
33 #endif
34 
35 #ifdef div
36 #error div is defined
37 #endif
38 
39 #ifdef ldiv
40 #error ldiv is defined
41 #endif
42 
43 #ifdef lldiv
44 #error lldiv is defined
45 #endif
46 
47 #ifndef EXIT_FAILURE
48 #error EXIT_FAILURE not defined
49 #endif
50 
51 #ifndef EXIT_SUCCESS
52 #error EXIT_SUCCESS not defined
53 #endif
54 
55 #ifndef MB_CUR_MAX
56 #error MB_CUR_MAX not defined
57 #endif
58 
59 #ifndef NULL
60 #error NULL not defined
61 #endif
62 
63 #ifndef RAND_MAX
64 #error RAND_MAX not defined
65 #endif
66 
main()67 int main()
68 {
69     size_t s = 0; ((void)s);
70     div_t d; ((void)d);
71     ldiv_t ld; ((void)ld);
72     lldiv_t lld; ((void)lld);
73     char** endptr = 0;
74     static_assert((std::is_same<decltype(atof("")), double>::value), "");
75     static_assert((std::is_same<decltype(atoi("")), int>::value), "");
76     static_assert((std::is_same<decltype(atol("")), long>::value), "");
77     static_assert((std::is_same<decltype(atoll("")), long long>::value), "");
78     static_assert((std::is_same<decltype(getenv("")), char*>::value), "");
79     static_assert((std::is_same<decltype(strtod("", endptr)), double>::value), "");
80     static_assert((std::is_same<decltype(strtof("", endptr)), float>::value), "");
81     static_assert((std::is_same<decltype(strtold("", endptr)), long double>::value), "");
82     static_assert((std::is_same<decltype(strtol("", endptr,0)), long>::value), "");
83     static_assert((std::is_same<decltype(strtoll("", endptr,0)), long long>::value), "");
84     static_assert((std::is_same<decltype(strtoul("", endptr,0)), unsigned long>::value), "");
85     static_assert((std::is_same<decltype(strtoull("", endptr,0)), unsigned long long>::value), "");
86     static_assert((std::is_same<decltype(rand()), int>::value), "");
87     static_assert((std::is_same<decltype(srand(0)), void>::value), "");
88 
89 //  Microsoft does not implement aligned_alloc in their C library
90 #if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && !defined(_WIN32)
91     static_assert((std::is_same<decltype(aligned_alloc(0,0)), void*>::value), "");
92 #endif
93 
94     static_assert((std::is_same<decltype(calloc(0,0)), void*>::value), "");
95     static_assert((std::is_same<decltype(free(0)), void>::value), "");
96     static_assert((std::is_same<decltype(malloc(0)), void*>::value), "");
97     static_assert((std::is_same<decltype(realloc(0,0)), void*>::value), "");
98     static_assert((std::is_same<decltype(abort()), void>::value), "");
99     static_assert((std::is_same<decltype(atexit(0)), int>::value), "");
100     static_assert((std::is_same<decltype(exit(0)), void>::value), "");
101     static_assert((std::is_same<decltype(_Exit(0)), void>::value), "");
102     static_assert((std::is_same<decltype(getenv("")), char*>::value), "");
103     static_assert((std::is_same<decltype(system("")), int>::value), "");
104     static_assert((std::is_same<decltype(bsearch(0,0,0,0,0)), void*>::value), "");
105     static_assert((std::is_same<decltype(qsort(0,0,0,0)), void>::value), "");
106     static_assert((std::is_same<decltype(abs(0)), int>::value), "");
107     static_assert((std::is_same<decltype(labs((long)0)), long>::value), "");
108     static_assert((std::is_same<decltype(llabs((long long)0)), long long>::value), "");
109     static_assert((std::is_same<decltype(div(0,0)), div_t>::value), "");
110     static_assert((std::is_same<decltype(ldiv(0L,0L)), ldiv_t>::value), "");
111     static_assert((std::is_same<decltype(lldiv(0LL,0LL)), lldiv_t>::value), "");
112     wchar_t* pw = 0;
113     const wchar_t* pwc = 0;
114     char* pc = 0;
115     static_assert((std::is_same<decltype(mblen("",0)), int>::value), "");
116     static_assert((std::is_same<decltype(mbtowc(pw,"",0)), int>::value), "");
117     static_assert((std::is_same<decltype(wctomb(pc,L' ')), int>::value), "");
118     static_assert((std::is_same<decltype(mbstowcs(pw,"",0)), size_t>::value), "");
119     static_assert((std::is_same<decltype(wcstombs(pc,pwc,0)), size_t>::value), "");
120 }
121