basysKom Toolbox

11 – Treat compiler warnings as errors

Treat compiler warnings as errors

Goals

Prevent problematic code from silently “creeping” in.

Description

Modern C and C++ compilers are quite good at generating warnings for problematic issues. By default a warning will not stop the compiler from generating code. Consider to treat compiler warnings as errors to prevent issues from creeping into your code base.

Environment

C, C++, Qt

Platform

All

Implementation effort

Minor, given that your project is already compiling without warnings.

Applicability

All projects with a clearly defined target toolchain.

Caveats

  • Treating warnings as errors can be a considerable headache if there is a large range of toolchains/platforms to support as warnings generated might change over time.
  • Do not enable “warning as errors” for releases that are consumed by an undefined and wide-ranging user base (for example when releasing software with-in your organization, to customers or as open source).

See also

Implementation hints

  • gcc/clang: -WError
  • Visual Studio: /WX switch or „Treat Warnings as Errors“ in project properties
  • Newer compiler versions tend to emit more warnings. The same compiler targeting a different platform might generate slightly different warnings. Make sure there is a central build flag as an escape hatch. Have a CI system in place to enforce “warnings as errors” for your officially supported toolchain(s).
About the Toolbox

The basysKom Toolbox is a state-of-the-art collection of best practices in agile management and software development and a valuable tool for every kickoff meeting.

These cards can be used during a project kickoff in order to select best fitting good practices from the very start of your project, but also as a reminder during the course of a project implementation. Every card holds a QR code with additional information related to the specific tool, the tools’ applicability, known constraints and additional tips on how to implement it in a project setup.

You can provide us feedback on GitHub.

Toolbox

basysKom Newsletter

We collect only the data you enter in this form (no IP address or information that can be derived from it). The collected data is only used in order to send you our regular newsletters, from which you can unsubscribe at any point using the link at the bottom of each newsletter. We will retain this information until you ask us to delete it permanently. For more information about our privacy policy, read Privacy Policy