#include <stddef.h>
#if __STDC_VERSION__ - 0 >= 202311L
#if __STDC_VERSION_STDDEF_H__ - 0 < 202311L
#error __STDC_VERSION_STDDEF_H__ not defined appropriately
#endif
#endif
typedef ptrdiff_t nbtest_ptrdiff_t;
typedef size_t nbtest_size_t;
#if __STDC_VERSION__ - 0 >= 201112L
typedef max_align_t nbtest_max_align_t;
#endif
typedef wchar_t nbtest_wchar_t;
#if __STDC_VERSION__ - 0 >= 202311L
typedef nullptr_t nbtest_nullptr_t;
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_stddef.c,v 1.1 2025/04/01 00:33:55 riastradh Exp $");
#include <atf-c.h>
#include <stdalign.h>
ATF_TC(macros);
ATF_TC_HEAD(macros, tc)
{
atf_tc_set_md_var(tc, "descr", "Test <stddef.h> macros work");
}
ATF_TC_BODY(macros, tc)
{
void *volatile pNULL = NULL;
#if __STDC_VERSION__ - 0 >= 202311L
void *volatile pnullptr = nullptr;
#endif
struct s { char x[3], y; };
size_t o;
ATF_CHECK(!pNULL);
#if __STDC_VERSION__ - 0 >= 202311L
ATF_CHECK(!pnullptr);
#endif
#if __STDC_VERSION__ - 0 >= 202311L
volatile enum { A, B } x = A;
switch (x) {
case A:
break;
case B:
default:
unreachable();
}
#endif
ATF_CHECK_MSG((o = offsetof(struct s, y)) == 3,
"o=%zu", o);
}
ATF_TC(types);
ATF_TC_HEAD(types, tc)
{
atf_tc_set_md_var(tc, "descr", "Test <stddef.h> types are reasonable");
}
ATF_TC_BODY(types, tc)
{
#ifdef __GNUC__
char *p, *q;
ATF_CHECK(__builtin_types_compatible_p(ptrdiff_t, typeof(p - q)));
ATF_CHECK(__builtin_types_compatible_p(size_t, typeof(sizeof(p))));
#if __STDC_VERSION__ - 0 >= 202311L
ATF_CHECK(__builtin_types_compatible_p(nullptr_t, typeof(nullptr)));
#endif
#endif
#if __STDC_VERSION__ - 0 >= 201112L
size_t a;
ATF_CHECK_MSG((a = alignof(max_align_t)) >= alignof(long long),
"a=%zu", a);
ATF_CHECK_MSG((a = alignof(max_align_t)) >= alignof(long double),
"a=%zu", a);
ATF_CHECK_MSG((a = alignof(max_align_t)) >= alignof(void *),
"a=%zu", a);
ATF_CHECK_MSG((a = alignof(max_align_t)) >= alignof(int (*)(void)),
"a=%zu", a);
#endif
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, macros);
ATF_TP_ADD_TC(tp, types);
return atf_no_error();
}