xref: /llvm-project/libcxx/test/std/depr/depr.c.headers/stddef_h.compile.pass.cpp (revision 9dfb142ce0bfa11ea7cd9176c27b6c0fca7243e0)
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 
13 #include "test_macros.h"
14 
use()15 void use() {
16     // Make sure we can use the following types without including anything else
17     (void)sizeof(size_t);
18     (void)sizeof(ptrdiff_t);
19 #if TEST_STD_VER >= 11
20     (void)sizeof(nullptr);
21     (void)sizeof(nullptr_t);
22     (void)sizeof(max_align_t);
23 #endif
24 }
25 
26 #ifndef NULL
27 #error NULL not defined
28 #endif
29 
30 #ifndef offsetof
31 #error offsetof not defined
32 #endif
33 
34 #include <type_traits>
35 
36 static_assert(sizeof(size_t) == sizeof(void*), "");
37 static_assert(std::is_unsigned<size_t>::value, "");
38 static_assert(std::is_integral<size_t>::value, "");
39 static_assert(sizeof(ptrdiff_t) == sizeof(void*), "");
40 static_assert(std::is_signed<ptrdiff_t>::value, "");
41 static_assert(std::is_integral<ptrdiff_t>::value, "");
42 static_assert((std::is_same<decltype(nullptr), nullptr_t>::value), "");
43 static_assert(sizeof(nullptr_t) == sizeof(void*), "");
44 #if TEST_STD_VER >= 11
45 #  if TEST_STD_VER >= 20
46 // P0767
47 static_assert(std::is_trivial<max_align_t>::value, "");
48 static_assert(std::is_standard_layout<max_align_t>::value, "");
49 #  else
50 static_assert(std::is_pod<max_align_t>::value, "");
51 #  endif
52 static_assert(std::alignment_of<max_align_t>::value >= std::alignment_of<long long>::value, "");
53 static_assert(std::alignment_of<max_align_t>::value >= std::alignment_of<long double>::value, "");
54 static_assert(std::alignment_of<max_align_t>::value >= std::alignment_of<void*>::value, "");
55 #endif // TEST_STD_VER >= 11
56