test-stddef: test for (some) offsetof bugs
authorEric Blake <eblake@redhat.com>
Mon, 16 Aug 2010 23:34:45 +0000 (17:34 -0600)
committerEric Blake <eblake@redhat.com>
Tue, 17 Aug 2010 14:09:20 +0000 (08:09 -0600)
See the mailing list for a more comprehensive patch that works
around the Solaris bug.

* 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.

Signed-off-by: Eric Blake <eblake@redhat.com>
ChangeLog
doc/posix-headers/stddef.texi
tests/test-stddef.c

index 86de94d..20a5adc 100644 (file)
--- 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.
index 84db56c..829447c 100644 (file)
@@ -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
index d047e57..2c392c7 100644 (file)
@@ -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)
 {