summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--doc/posix-headers/stddef.texi7
-rw-r--r--tests/test-stddef.c14
3 files changed, 29 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 86de94dde6..20a5adc1dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-08-17 Eric Blake <eblake@redhat.com>
+
+ test-stddef: test for (some) offsetof bugs
+ * tests/test-stddef.c: Enhance test to ensure correct type of
+ offsetof.
+ * doc/posix-headers/stddef.texi (stddef.h): Document a Solaris bug
+ that we are not fixing at this time.
+
2010-08-15 Bruno Haible <bruno@clisp.org>
stpncpy: Allow stpncpy to be defined as a macro.
diff --git a/doc/posix-headers/stddef.texi b/doc/posix-headers/stddef.texi
index 84db56c0cb..829447ca37 100644
--- a/doc/posix-headers/stddef.texi
+++ b/doc/posix-headers/stddef.texi
@@ -18,4 +18,11 @@ NetBSD 5.0
Portability problems not fixed by Gnulib:
@itemize
+@item
+Some platforms provide an @code{offsetof} macro that cannot be used in
+arbitrary expressions:
+Solaris 10
+This problem can be worked around by parenthesizing the
+@code{offsetof} expression in the unlikely case you use it with
+@code{sizeof} or @samp{[]}.
@end itemize
diff --git a/tests/test-stddef.c b/tests/test-stddef.c
index d047e57b65..2c392c7547 100644
--- a/tests/test-stddef.c
+++ b/tests/test-stddef.c
@@ -31,6 +31,20 @@ size_t c = 2;
per POSIX 2008. */
verify (sizeof NULL == sizeof (void *));
+/* Check that offsetof produces integer constants with correct type. */
+struct d
+{
+ char e;
+ char f;
+};
+/* Solaris 10 has a bug where offsetof is under-parenthesized, and
+ cannot be used as an arbitrary expression. However, since it is
+ unlikely to bite real code, we ignore that short-coming. */
+/* verify (sizeof offsetof (struct d, e) == sizeof (size_t)); */
+verify (sizeof (offsetof (struct d, e)) == sizeof (size_t));
+verify (offsetof (struct d, e) < -1); /* Must be unsigned. */
+verify (offsetof (struct d, f) == 1);
+
int
main (void)
{