Title | MPS produces warnings when compiled with -Wextra |
Status | closed |
Priority | nice |
Assigned user | Gareth Rees |
Organization | Ravenbrook |
Description | When compiled with clang -Wextra, the MPS fails to compile: arg.c:105:47: error: missing field 'val' initializer [-Werror,-Wmissing-field-initializers] ArgStruct mps_args_none[] = {{MPS_KEY_ARGS_END}}; When compiled with gcc -Wextra, the MPS also fails to compile: tract.c:146: warning: comparison of unsigned expression >= 0 is always true event.c:83: warning: comparison of unsigned expression >= 0 is always true poolawl.c:1308: warning: comparison of unsigned expression >= 0 is always true prmci3xc.c:38: warning: comparison of unsigned expression >= 0 is always true This problem came up when trying to integrate the MPS with Ruby, which compiles with -Wextra. In order to make integrations go smoothly, the MPS ought to compile under the most stringent compiler options like this. |
Analysis | The missing initializer can be fixed like this: ArgStruct mps_args_none[] = {{MPS_KEY_ARGS_END, {0}}}; The "comparison of unsigned expression >= 0 is always true" warnings are more awkward to fix. The typical case is event.c:83 AVER(0 <= kind && kind < EventKindLIMIT); where "0 <= kind" is always true, but it conveys the information that we have thought about the range of values. Here are some ideas for fixing this: 1. Replace "0 <= kind" with "(0 == kind || 0 < kind)". Ugh! Also, a sufficiently clever compiler could probably warn us about this in the future. 2. Replace "0 <= kind" with a comment along the lines of /* "0 <= kind" is always true since kind is unsigned */ I couldn't find a way of locally suppressing the warning. |
How found | manual_test |
Evidence | None |
Created by | Gareth Rees |
Created on | 2013-09-30 16:28:18 |
Last modified by | Gareth Rees |
Last modified on | 2013-10-01 14:28:10 |
History | 2013-09-30 GDR Created. |
Change | Effect | Date | User | Description |
---|---|---|---|---|
183505 | closed | 2013-10-01 14:27:52 | Gareth Rees | Use macro NONNEGATIVE so that we can keep asserting that values are >= 0 without provoking "unsigned comparison >= 0 is always true" warnings from GCC. |
183501 | closed | 2013-10-01 11:10:59 | Gareth Rees | Avoid comparison of unsigned >= 0 so that we can compile without warnings under gcc -Wextra. |
183498 | open | 2013-10-01 10:52:45 | Gareth Rees | Avoid warnings when compiling with -Wwrite-strings: * Use const char * in places where we want to assign string constants. Avoid warnings when compiling with -Wextra: * Avoid if statement with empty body in amcsshe.c * Avoid comparison of unsigned >= 0. |
183494 | open | 2013-09-30 17:18:52 | Gareth Rees | Turn on -Wextra -Wwrite-strings when compiling with GCC or Clang. Add missing initializer to mps_args_none. Change "char *" to "const char *" where necessary. |