On Mon 14 Jan 2019 at 15:44:32 +0100, Thomas Klausner wrote: > > When compiling some software (like finance/gnucash) with clang 7.0.0 > (but not with gcc!) on NetBSD-8.99.30/amd64, compilation fails with: > > (this one's from www/tidy because I don't have the gnucash error handy): > > array subscript is of type 'char' [-Wchar-subscripts] > ... > /usr/include/sys/ctype_inline.h:59:46: note: expanded from macro 'tolower' > #define tolower(c) ((int)((_tolower_tab_ + 1)[(c)])) > ^~~~ > > The standard workaround is to cast arguments to (unsigned char). I've > provided patches for gnucash for that, but they received pushback > because the compiler shouldn't error out on this undefined behaviour. > (gnucash upstream is happy with it dumping core at runtime) > > Here's the bug report with more details. > > https://bugs.gnucash.org/show_bug.cgi?id=797039 > > Is there something we can improve in the NetBSD headers so that clang > doesn't behave more pickily and gcc in this case? What I would write in reply to comment 12 by John Ralls, which goes } Even casting the arg to *signed char* silences the warning, so the } warning isn't really about signedness at all, it's that 0xa3 might be a } positive value on some machines and a negative one on others and that } might produce surprising results when used as an array dereference. So } the warning isn't that silly, NetBSD's ctype implementation is } deficient. would be something like | Exactly values like you mention are the problem. If a char (which has | unknown signedness) containing 0xa3 is passed to a ctype(3) macro, and | char happens to be signed, then the application program invokes | undefined behaviour (because a value outside of the allowable range is | passed). It is definitely not the library doing something undefined, | since the library is part of the implementation. | | The fact that the compiler warns the user if they make a mistake like | this is a useful feature and exactly as intended (although the error | message might be nicer). | | Now if you explicitly pass a signed char, then the user is presumed to | know what they are doing, and not warning is defendable. | | In summary, it is the application which is incorrect here. but I haven't bothered to make a login at the gnucash site. -Olaf. -- ___ Olaf 'Rhialto' Seibert -- "What good is a Ring of Power \X/ rhialto/at/falu.nl -- if you're unable...to Speak." - Agent Elrond
Attachment:
signature.asc
Description: PGP signature