1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8
9 // <stddef.h>
10
11 #include <stddef.h>
12 #include <cassert>
13 #include <type_traits>
14
15 #include "test_macros.h"
16
17 #ifndef NULL
18 #error NULL not defined
19 #endif
20
21 #ifndef offsetof
22 #error offsetof not defined
23 #endif
24
main(int,char **)25 int main(int, char**)
26 {
27 void *p = NULL;
28 assert(!p);
29
30 static_assert(sizeof(size_t) == sizeof(void*),
31 "sizeof(size_t) == sizeof(void*)");
32 static_assert(std::is_unsigned<size_t>::value,
33 "std::is_unsigned<size_t>::value");
34 static_assert(std::is_integral<size_t>::value,
35 "std::is_integral<size_t>::value");
36 static_assert(sizeof(ptrdiff_t) == sizeof(void*),
37 "sizeof(ptrdiff_t) == sizeof(void*)");
38 static_assert(std::is_signed<ptrdiff_t>::value,
39 "std::is_signed<ptrdiff_t>::value");
40 static_assert(std::is_integral<ptrdiff_t>::value,
41 "std::is_integral<ptrdiff_t>::value");
42 static_assert((std::is_same<decltype(nullptr), nullptr_t>::value),
43 "decltype(nullptr) == nullptr_t");
44 static_assert(sizeof(nullptr_t) == sizeof(void*),
45 "sizeof(nullptr_t) == sizeof(void*)");
46 #if TEST_STD_VER >= 11
47 #if TEST_STD_VER > 17
48 // P0767
49 static_assert(std::is_trivial<max_align_t>::value,
50 "std::is_trivial<max_align_t>::value");
51 static_assert(std::is_standard_layout<max_align_t>::value,
52 "std::is_standard_layout<max_align_t>::value");
53 #else
54 static_assert(std::is_pod<max_align_t>::value,
55 "std::is_pod<max_align_t>::value");
56 #endif
57 static_assert((std::alignment_of<max_align_t>::value >=
58 std::alignment_of<long long>::value),
59 "std::alignment_of<max_align_t>::value >= "
60 "std::alignment_of<long long>::value");
61 static_assert(std::alignment_of<max_align_t>::value >=
62 std::alignment_of<long double>::value,
63 "std::alignment_of<max_align_t>::value >= "
64 "std::alignment_of<long double>::value");
65 static_assert(std::alignment_of<max_align_t>::value >=
66 std::alignment_of<void*>::value,
67 "std::alignment_of<max_align_t>::value >= "
68 "std::alignment_of<void*>::value");
69 #endif
70
71 return 0;
72 }
73