Mercurial > hg > octave-lojdl > gnulib-hg
changeset 13559:3c81a57b5a1d
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 <eblake@redhat.com>
author | Eric Blake <eblake@redhat.com> |
---|---|
date | Mon, 16 Aug 2010 17:34:45 -0600 |
parents | 263949fe34ae |
children | 8370fed98298 |
files | ChangeLog doc/posix-headers/stddef.texi tests/test-stddef.c |
diffstat | 3 files changed, 29 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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.
--- a/doc/posix-headers/stddef.texi +++ b/doc/posix-headers/stddef.texi @@ -18,4 +18,11 @@ 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
--- a/tests/test-stddef.c +++ b/tests/test-stddef.c @@ -31,6 +31,20 @@ 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) {