Open yurivict opened 4 years ago
Or you might say "clang wrongfully complains" because "if(x = y)" is perfectly valid C syntax (set x to the value of y and then execute the conditional based on whether x is 0 or 1).
This is a safeguard against a very common error when if (a = b)
is meant to be a comparison. This catches a lot of programming errors, and this is a very infrequent use pattern. If your project uses this pattern, in order to silence this warning you should add -Wno-parentheses
.
The if (a = b)
case can be silenced by using if ((a = b))
, the second pair of parentheses tells the compiler "yes, this is an assignment, evaluate the value as a boolean expression). But it is much more readable to do an explicit assignment, especially when used in a for loop, e.g. for ( count = 1; nextEdge = (YEDGEPTR) Ygraph_listAdjEdges(node,count);
@StefanBruens What about errors?
Currently clang fails to compile graywolf
.
Could you please make sure that clang compiles it?
Thanks. Yuri
I'm not sure what the further action here is. Compiling with -Wall creates tons of warnings, some of which are not just nitpicking. IMHO, warnings about assignments in if-statements should always be handled by either fixing it or (if intended) silenced by double parentheses. Also there are a lot of wrong printf formatting directives (wrong integer type, for instance). I'm happy starting to fix these, I'd just like to know if there is any intention on fixing these/accepting appropriate pull requests. I would be happy to hear more in this matter :)
clang-8 rightfully complains: