Maybe one good exercise would be to ask programmers to write some program, and then let people vote on which code is the simplest to read and to understand.
So while that warning can certainly be useless information, it does definitely catch bugs. Unfortunately, the people who write code like the above are also more likely to be people who ignore warnings. ;-)
#include <string.h>
struct S {
int i;
char c;
int j;
};
void f(void) {
struct S s1 = { 0, 0, 0 }, s2 = { 0, 0, 0 };
memcpy(&s1, &s2, 9);
}
int main(void) {
f();
return 0;
}
MSVC, Clang, and PC-Lint are all silent on the code (which is reasonable behavior since it's impossible to glean programmer intent from that snippet -- maybe the programmer really only wants the first nine bytes!). (Btw, yes, I am using the analyzer features for MSVC and Clang, not just relying on high warning levels.)All current compilers also have mechanisms to selectively ignore warnings via pragmas, like '#pragma GCC diagnostic ignored "-Wfoo"' in clang and GCC, which can be used to suppress instances of false positives of otherwise useful warnings.
https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html
http://msdn.microsoft.com/en-us/library/aa273936.aspx
IMHO not using -Werror is just inexcusable.
1 - Some tools and libraries (like GTK - yeah) like to throw unfixable warnings. "Yeah, this platform is missing this feature so let's throw a warning"
2 - Sometimes fixing a warning results in something much more complicated than the original code. (see for example half of PyLint warnings)
So, for that to work it's important the tool warnings are good (and at least with GCC on C they usually are)
But yes, that is a huge pet peeve of mine. I have all my QT header includes wrapped with pragmas to turn off warning because otherwise they spit out endless, useless warnings.
So when you go to do a minor fix, do you also touch other code that now triggers a warning?
Or worse, they break existing code (I've seen this happen with C++ on GCC)
Haven't tried Clang because I am on Windows for my C++ stuff.
Wow, am I ever frustrated by the summary ignoring of warnings I see going on around me. I spend my spare time at work making warnings go away and deleting uncommented @SupressWarnings from our codebase.
In a word, KISS. Another engineer designing critical systems for the US government coined that one, apparently [1].
[1] http://en.wikipedia.org/wiki/KISS_principle