I've been toying with some gcc warnings lately, and this could generate some new ideas for janitorial tasks. For example:
o -Wmissing-declarations should point lots of missing APIs declarations (I've done it in some cases, and I'm in the process of submitting some fixes). We cannot turn this warning always on because there are lots of cases where we have global functions without prototypes (most than 2/3 of them are made out of the 16bit entry points)
o -Wcast-qual should point out all the (const bla*) => (foo*) casts. We use quite a bit this, and in some cases it would prevent some errors. These are the main cases pointed out by this warning: 1/ const void* ptr; and then reading a value from ptr (word...) like *(WORD*)ptr which should be written *(const WORD*). The warning in this case is harmless. 2/ const void* ptr; and then setting it to another const pointer: const WORD* pw = (WORD*)ptr; which should be written pw = (const WORD*)ptr;. This warning is harmless if pw is really defined as const, in some cases it isn't and this should be fixed. 3/ const void* ptr; and then setting it to a pointer to a pointer (used a lot for qsort/bsearch... callbacks), when dealing with arrays of pointers. Here again, what's const is the first pointer, so const foo* f = *(const foo**)ptr is wrong, it should be const foo* f = (const foo* const*)ptr; This could be harmfull if not declared properly. Unfortunately, we cannot turn this warning on all the time because some C functions implementation would always trigger it (strstr for example), unless we use intergral values (not pointer) to cast from the const char* to the returned char*), and this is uglier IMO than the warning we try to avoid.
Some others warnings could be used as well. Trying also the Intel compiler gave lots of interesting warnings (and a tons of not so usefull too).
A+
Here are a couple extra suggestions:
* Add -Wwrite-strings There has already been quite some work on this but I believe it's not finished yet. I'm not 100% sure of the status though.
* Patch ou min/max macros to catch signed/unsigned comparisons. This generates a lot of warnings. Ideally they should be fixed without using casts but it may not always be possible.
(the modified min/max macros where borrowed from a Linux kernel patch)
Index: include/minmax.h =================================================================== RCS file: /var/cvs/wine/include/minmax.h,v retrieving revision 1.2 diff -u -r1.2 minmax.h --- a/include/minmax.h 10 Mar 2002 00:02:34 -0000 1.2 +++ b/include/minmax.h 18 Oct 2003 11:34:30 -0000 @@ -21,11 +21,34 @@ #ifndef __WINE_MINMAX_H #define __WINE_MINMAX_H
+#if (defined(WINE_MINMAX) || defined(__WINESRC__)) && defined(__GNUC__) +#ifndef max +#define max(x,y) \ + ({ const typeof(x) _x = x; \ + const typeof(y) _y = y; \ + \ + (void) (&_x == &_y); \ + \ + (typeof(x))(_x > _y ? _x : _y); \ + }) +#endif +#ifndef min +#define min(x,y) \ + ({ const typeof(x) _x = x; \ + const typeof(y) _y = y; \ + \ + (void) (&_x == &_y); \ + \ + (typeof(x))(_x < _y ? _x : _y); \ + }) +#endif +#else #ifndef max #define max(a,b) (((a) > (b)) ? (a) : (b)) #endif #ifndef min #define min(a,b) (((a) < (b)) ? (a) : (b)) #endif +#endif
#endif /* __WINE_MINMAX_H */ Index: include/windef.h =================================================================== RCS file: /var/cvs/wine/include/windef.h,v retrieving revision 1.89 diff -u -r1.89 windef.h --- a/include/windef.h 24 Sep 2003 05:26:00 -0000 1.89 +++ b/include/windef.h 11 Oct 2003 11:02:29 -0000 @@ -272,12 +272,37 @@
/* min and max macros */ #ifndef NOMINMAX + +#if (defined(WINE_MINMAX) || defined(__WINESRC__)) && defined(__GNUC__) +#ifndef max +#define max(x,y) \ + ({ const typeof(x) _x = x; \ + const typeof(y) _y = y; \ + \ + (void) (&_x == &_y); \ + \ + (typeof(x))(_x > _y ? _x : _y); \ + }) +#endif +#ifndef min +#define min(x,y) \ + ({ const typeof(x) _x = x; \ + const typeof(y) _y = y; \ + \ + (void) (&_x == &_y); \ + \ + (typeof(x))(_x < _y ? _x : _y); \ + }) +#endif +#else #ifndef max #define max(a,b) (((a) > (b)) ? (a) : (b)) #endif #ifndef min #define min(a,b) (((a) < (b)) ? (a) : (b)) #endif +#endif + #endif /* NOMINMAX */
#ifdef MAX_PATH /* Work-around for Mingw */