From: Bruno Haible Date: Sun, 25 May 2025 19:50:12 +0000 (+0200) Subject: stddef-h tests: Add more C++ tests. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5da9ed4ca27c28d9de3e28cf9a755eb72c19c016;p=thirdparty%2Fgnulib.git stddef-h tests: Add more C++ tests. * tests/test-stddef-h-c++2.cc: Test the expected contents of . --- diff --git a/ChangeLog b/ChangeLog index e9c55ad680..bf5b782640 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2025-05-25 Bruno Haible + + stddef-h tests: Add more C++ tests. + * tests/test-stddef-h-c++2.cc: Test the expected contents of . + 2025-05-25 Bruno Haible selinux-h: Fix error with MSVC. diff --git a/tests/test-stddef-h-c++2.cc b/tests/test-stddef-h-c++2.cc index d2588e1227..e207976d13 100644 --- a/tests/test-stddef-h-c++2.cc +++ b/tests/test-stddef-h-c++2.cc @@ -18,3 +18,31 @@ #include #include + +/* Test the expected contents of , cf. + . */ + +/* Check that appropriate types are defined. */ +ptrdiff_t b = 1; +size_t c = 2; + +#if !defined __cplusplus || defined __GNUC__ || defined __clang__ +/* Check that NULL can be passed through varargs as a pointer type, + per POSIX 2008. */ +static_assert (sizeof NULL == sizeof (void *)); +#endif + +/* Check that offsetof produces integer constants with correct type. */ +struct d +{ + char e; + char f; +}; +static_assert (sizeof (offsetof (struct d, e)) == sizeof (size_t)); +static_assert (offsetof (struct d, f) == 1); + +#include /* INT_MAX */ + +/* offsetof promotes to an unsigned integer if and only if sizes do + not fit in int. */ +static_assert ((offsetof (struct d, e) < -1) == (INT_MAX < (size_t) -1));