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