On 25-3-2014 0:20, mathog wrote:
On 22-Mar-2014 06:16, su_v wrote:
-Wno-error=self-assign
more errors:
../../src/libuemf/uwmf_endian.c:285:10: error: explicitly assigning a variable of type 'int' to itself [-Werror,-Wself-assign]
Sometimes you can't win.
The line with the warning is the second one below:
void U_WMRCORE_SIZE16_swap(char *record, int torev){ torev = torev; // shuts up compiler warnings about unused parameters U_swap4(record, 1); /* Size16_4 is at offset 0 in U_METARECORD */ }
where this is one of those situations where there are a large number of functions all use the same argument list, but some of them don't actually use some of the arguments. The
torev = torev
trick is one way to silence the "unused argument" warning in gcc and last time I checked it worked for several other compilers as well, like Sun's compiler. Apparently not for clang though. Note this is in a C module, so the C++ syntax to indicate an unused argument will not work. AFAIK the C language specification provides no standard way to eliminate this warning or its evil twin "statement with no effect", which is what you get if you try to finesse this situation with:
(void) torev;
Note, the other similar clang warnings are all for the same thing.
The problem is that torev = torev is not instructive as to what it is doing. [*] The self-assignment may actually have side-effects for C++ objects, so for us such a line looks very suspicious.
A much better way (and more generally accepted I believe) is what I already did in a number of places in libuemf: http://bazaar.launchpad.net/~inkscape.dev/inkscape/trunk/revision/13182
Thanks for writing code that people other than you can maintain, Johan
[*] So it may have been a bug (consider typos). The compiler are there to help you, not to bug you. I have already found a ton of bugs simply by listening to the compiler's warnings. Please don't fool yourself you are smarter than the compiler(makers). I am pretty sure we all aren't.