]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
stddef-h tests: Add more C++ tests.
authorBruno Haible <bruno@clisp.org>
Sun, 25 May 2025 19:50:12 +0000 (21:50 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 25 May 2025 19:50:27 +0000 (21:50 +0200)
* tests/test-stddef-h-c++2.cc: Test the expected contents of <cstddef>.

ChangeLog
tests/test-stddef-h-c++2.cc

index e9c55ad680f28786bf57c83d44cb090edf8a145d..bf5b7826403db30a464a2e442b7cb27542576a3c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2025-05-25  Bruno Haible  <bruno@clisp.org>
+
+       stddef-h tests: Add more C++ tests.
+       * tests/test-stddef-h-c++2.cc: Test the expected contents of <cstddef>.
+
 2025-05-25  Bruno Haible  <bruno@clisp.org>
 
        selinux-h: Fix error with MSVC.
index d2588e122754f30aa241d53457e5f9fee5e4bdb4..e207976d133ffa603025a20aa132cf759ff77550 100644 (file)
 #include <config.h>
 
 #include <cstddef>
+
+/* Test the expected contents of <cstddef>, cf.
+   <https://en.cppreference.com/w/cpp/header/cstddef>.  */
+
+/* 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 <limits.h> /* 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));