3 ms·
> No, if you get warnings, it means that your code is (and was already) wrong. No, that's not right, otherwise they wouldn't be warnings. The whole point of th
by saagarjha 5y ago
> No, if you get warnings, it means that your code is (and was already) wrong.
No, that's not right, otherwise they wouldn't be warnings. The whole point of them existing is the compiler trying to alert you of a suspicious construct, but it's not confident enough to be sure it's a bug. Sometimes I want to use assignment for its result–that's not a bug, it's just something that is often done accidentally.
- tialaramex 5y agoThere's a big language problem here. It's not the whole of the issue, but it's certainly a big component. In C and C++ there are a huge number of things that are legal, and thus must not cause an error diagnostic (out of the box) - and yet are obviously not what anybody should do (and so a warning diagnostic is appropriate if the compiler can successfully diagnose them). You give the example of "sometimes I want to use assignment for its result". A better language outright forbids this. If you want the result, write that, if you want an assignment, write that, if you want both, write both so that it's clear what you intended, and let the optimiser turn your clear program into efficient machine code rather than trying to out-guess the machine. Ideally warnings would not be red flags. If warnings are stuff like "This variable's name start with a capital letter when that's contrary to standard style guides." or "You keep saying 15 in this program, have you considered just defining a constant instead for whatever 15 is?" then you're in a better place, but unfortunately in C the warning is more likely to be "99.99% of the time this code is a buffer overflow, so, you probably don't mean that" or "It looks like this does X doesn't it? But, it actually does nothing at all, and for complicated reasons we can't make it do X, so, I really hope you didn't mean X."
- josefx 5y ago> but unfortunately in C the warning is more likely to be "99.99% of the time this code is a buffer overflow, so, you probably don't mean that" In my experience it is more likely that 0.01% of the time this signed to unsigned conversion (the one in the if block checking value ranges) can cause issues, please explicitly cast it to silence the warning.
- saagarjha 5y agoFWIW I stand by my argument pretty much regardless of language. (Most newer languages lack static analysis to the extent that C/C++ do, partially because many of the things are hard errors, and partially because nobody has gotten around to them yet.)
- jcelerier 5y agoDid you even look at the link I sent ? The warnings kindly tell you about actual undefined behaviour that is 100% a bug, like what -Wstrict-aliasing or -Wreturn-type reports
- saagarjha 5y agoYeah, I did. What you wrote was almost certainly a mistake (although, it's not guaranteed: one can image a macro expanding to such a tautology). But this is far from a convincing argument that all warnings indicate mistakes.
- jcelerier 5y agoThis exact mistake used to be in e.g. Qt, KDE, and Chromium code. That shit causes real world damage !