On 05/14/2015 03:06 PM, Eric Blake wrote: > On 05/14/2015 02:38 PM, Stefan Weil wrote: >> i686-w64-mingw32-gcc 4.9.1 from Debian Jessie complains: >> >> hw/pci/pci.c:938:29: warning: >> array subscript is above array bounds [-Warray-bounds] >> >> Using g_assert instead of assert fixes this warning. > > Is that because the mingw headers don't properly mark the expansion of > the failed branch of assert() as noreturn, whereas g_assert() does, and > therefore the compiler has more information about what variables must be > if the rest of the function is reached? >
> > Meanwhile, you may want to file a bug to the mingw maintainers that > their header is puny when compared to glibc assert() or to glib's > g_assert, when it comes to giving gcc decent hints. Oh, I was right! glibc /usr/include/assert.h: extern void __assert_fail (const char *__assertion, const char *__file, unsigned int __line, const char *__function) __THROW __attribute__ ((__noreturn__)); # define assert(expr) \ ((expr) \ ? __ASSERT_VOID_CAST (0) \ : __assert_fail (__STRING(expr), __FILE__, __LINE__, __ASSERT_FUNCTION)) vs mingw /usr/i686-w64-mingw32/sys-root/mingw/include/assert.h: extern void __cdecl _assert (const char *_Message, const char *_File, unsigned _Line); #define assert(_Expression) \ (void) \ ((!!(_Expression)) || \ (_assert(#_Expression,__FILE__,__LINE__),0)) even though mingw has in that same file: void __cdecl _Exit(int) __MINGW_ATTRIB_NORETURN; so it is indeed a bug in the mingw headers that __MINGW_ATTRIB_NORETURN was not attached to _assert's declaration. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature