Search code examples
c++warnings

is it best practice to try to remove ALL compiler warnings with any means


our project manager recently set up a policy to request developers to remove ALL the compiler warnings. I understand some warnings really are easy to be removed, some are not so easier. So some developers uses every possible way to achieve the goal. For example, using explicit cast to cast double to float, float to int, signed to unsigned etc, etc. Since our code base is so large, over 20 years of 30-50 developers' work, I really doubt that how much this effort can really help us, if it does have some merits. Can anyone give some of your advice or arguments? our project uses C++.


Solution

  • Once you let compiler warnings slip, the 'real' warnings also get ignored as well. I can't count the number of times I've come onto a project with a ton of warnings, that with just a little care, were removed along with a bunch of very subtle bugs. Accidental assignment in an if, accidental fall-through in a switch or no default, accidental ; at the end of a for loop, unintentional type-cast etc. The warnings are there for a reason - use them. Yes, some are very pendantic, but just a little bit of work saves a lot of headache later on.

    Clean the warnings and keep them clean. You will write better code.