From: Eric Blake Date: Mon, 16 Aug 2010 23:34:45 +0000 (-0600) Subject: test-stddef: test for (some) offsetof bugs X-Git-Tag: v0.1~3928 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=6f730e7ae5225bf9eb36554d94805b97a72784bd;p=gnulib.git test-stddef: test for (some) offsetof bugs 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 --- diff --git a/ChangeLog b/ChangeLog index 86de94dde..20a5adc1d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-08-17 Eric Blake + + 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 stpncpy: Allow stpncpy to be defined as a macro. diff --git a/doc/posix-headers/stddef.texi b/doc/posix-headers/stddef.texi index 84db56c0c..829447ca3 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 d047e57b6..2c392c754 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) {