1 //===----------------------------------------------------------------------===//
3 // 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
7 //===----------------------------------------------------------------------===//
12 #include <type_traits>
15 #include "test_macros.h"
18 #error EXIT_FAILURE not defined
22 #error EXIT_SUCCESS not defined
26 #error MB_CUR_MAX not defined
30 #error NULL not defined
34 #error RAND_MAX not defined
37 template <class TestType
, class IntType
>
38 void test_div_struct() {
40 static_assert(sizeof(obj
) >= sizeof(IntType
) * 2, ""); // >= to account for alignment.
41 static_assert((std::is_same
<decltype(obj
.quot
), IntType
>::value
), "");
42 static_assert((std::is_same
<decltype(obj
.rem
), IntType
>::value
), "");
46 template <class T
, class = decltype(std::abs(std::declval
<T
>()))>
47 std::true_type
has_abs_imp(int);
49 std::false_type
has_abs_imp(...);
52 struct has_abs
: decltype(has_abs_imp
<T
>(0)) {};
56 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wabsolute-value")
57 static_assert((std::is_same
<decltype(std::abs((float)0)), float>::value
), "");
58 static_assert((std::is_same
<decltype(std::abs((double)0)), double>::value
), "");
60 (std::is_same
<decltype(std::abs((long double)0)), long double>::value
), "");
61 static_assert((std::is_same
<decltype(std::abs((int)0)), int>::value
), "");
62 static_assert((std::is_same
<decltype(std::abs((long)0)), long>::value
), "");
63 static_assert((std::is_same
<decltype(std::abs((long long)0)), long long>::value
),
65 static_assert((std::is_same
<decltype(std::abs((unsigned char)0)), int>::value
),
67 static_assert((std::is_same
<decltype(std::abs((unsigned short)0)), int>::value
),
69 static_assert((std::is_same
<decltype(std::abs((signed char)0)), int>::value
),
71 static_assert((std::is_same
<decltype(std::abs((short)0)), int>::value
),
73 static_assert((std::is_same
<decltype(std::abs((unsigned char)0)), int>::value
),
75 static_assert((std::is_same
<decltype(std::abs((char)0)), int>::value
),
78 static_assert(!has_abs
<unsigned>::value
, "");
79 static_assert(!has_abs
<unsigned long>::value
, "");
80 static_assert(!has_abs
<unsigned long long>::value
, "");
81 static_assert(!has_abs
<std::size_t>::value
, "");
85 assert(std::abs(-1.) == 1);
92 static_assert((std::is_same
<std::size_t, decltype(sizeof(int))>::value
), "");
93 test_div_struct
<std::div_t, int>();
94 test_div_struct
<std::ldiv_t, long>();
95 test_div_struct
<std::lldiv_t
, long long>();
97 static_assert((std::is_same
<decltype(std::atof("")), double>::value
), "");
98 static_assert((std::is_same
<decltype(std::atoi("")), int>::value
), "");
99 static_assert((std::is_same
<decltype(std::atol("")), long>::value
), "");
100 static_assert((std::is_same
<decltype(std::atoll("")), long long>::value
), "");
101 static_assert((std::is_same
<decltype(std::getenv("")), char*>::value
), "");
102 static_assert((std::is_same
<decltype(std::strtod("", endptr
)), double>::value
), "");
103 static_assert((std::is_same
<decltype(std::strtof("", endptr
)), float>::value
), "");
104 static_assert((std::is_same
<decltype(std::strtold("", endptr
)), long double>::value
), "");
105 static_assert((std::is_same
<decltype(std::strtol("", endptr
,0)), long>::value
), "");
106 static_assert((std::is_same
<decltype(std::strtoll("", endptr
,0)), long long>::value
), "");
107 static_assert((std::is_same
<decltype(std::strtoul("", endptr
,0)), unsigned long>::value
), "");
108 static_assert((std::is_same
<decltype(std::strtoull("", endptr
,0)), unsigned long long>::value
), "");
109 static_assert((std::is_same
<decltype(std::rand()), int>::value
), "");
110 static_assert((std::is_same
<decltype(std::srand(0)), void>::value
), "");
112 // std::aligned_alloc tested in cstdlib.aligned_alloc.compile.pass.cpp
115 void (*handler
)() = 0;
116 int (*comp
)(void const*, void const*) = 0;
117 static_assert((std::is_same
<decltype(std::calloc(0,0)), void*>::value
), "");
118 static_assert((std::is_same
<decltype(std::free(0)), void>::value
), "");
119 static_assert((std::is_same
<decltype(std::malloc(0)), void*>::value
), "");
120 static_assert((std::is_same
<decltype(std::realloc(0,0)), void*>::value
), "");
121 static_assert((std::is_same
<decltype(std::abort()), void>::value
), "");
122 static_assert((std::is_same
<decltype(std::atexit(handler
)), int>::value
), "");
123 static_assert((std::is_same
<decltype(std::exit(0)), void>::value
), "");
124 static_assert((std::is_same
<decltype(std::_Exit(0)), void>::value
), "");
125 static_assert((std::is_same
<decltype(std::getenv("")), char*>::value
), "");
126 static_assert((std::is_same
<decltype(std::system("")), int>::value
), "");
127 static_assert((std::is_same
<decltype(std::bsearch(pv
,pv
,0,0,comp
)), void*>::value
), "");
128 static_assert((std::is_same
<decltype(std::qsort(pv
,0,0,comp
)), void>::value
), "");
129 static_assert((std::is_same
<decltype(std::abs(0)), int>::value
), "");
130 static_assert((std::is_same
<decltype(std::abs((long)0)), long>::value
), "");
131 static_assert((std::is_same
<decltype(std::abs((long long)0)), long long>::value
), "");
132 static_assert((std::is_same
<decltype(std::labs((long)0)), long>::value
), "");
133 static_assert((std::is_same
<decltype(std::llabs((long long)0)), long long>::value
), "");
134 static_assert((std::is_same
<decltype(std::div(0,0)), std::div_t>::value
), "");
135 static_assert((std::is_same
<decltype(std::div(0L,0L)), std::ldiv_t>::value
), "");
136 static_assert((std::is_same
<decltype(std::div(0LL,0LL)), std::lldiv_t
>::value
), "");
137 static_assert((std::is_same
<decltype(std::ldiv(0L,0L)), std::ldiv_t>::value
), "");
138 static_assert((std::is_same
<decltype(std::lldiv(0LL,0LL)), std::lldiv_t
>::value
), "");
139 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
141 const wchar_t* pwc
= 0;
143 static_assert((std::is_same
<decltype(std::mblen("",0)), int>::value
), "");
144 static_assert((std::is_same
<decltype(std::mbtowc(pw
,"",0)), int>::value
), "");
145 static_assert((std::is_same
<decltype(std::wctomb(pc
,L
' ')), int>::value
), "");
146 static_assert((std::is_same
<decltype(std::mbstowcs(pw
,"",0)), std::size_t>::value
), "");
147 static_assert((std::is_same
<decltype(std::wcstombs(pc
,pwc
,0)), std::size_t>::value
), "");