#007 – Warnings and error levels

When the compiler encounters an issue it will emit a diagnostic message or diagnostic for short. The C++ standard does not define how diagnostic messages should be categorized, worded, or how those issues should affect the compilation of the program. However, compilers have adopted the following convention:

  • A diagnostic/compiler error causes the compiler to stop compilation because the error is serious
  • A diagnostic warning is an issue with the source code but compilation proceeds undisturbed

In the spirit of building robust programs, it’s good to increase the sensitivity for warning levels. Also, this provides extra diagnostics information which is helpful during debugging.

This differs according to the IDE. However, for VS Code, do the following

  1. Open the tasks.json file, find args, and then locate the line “${file}” within that section.
  2. Above the ${file} line, add new lines containing the following commands (one per line):
"-Wall",
"-Weffc++",
"-Wextra",
"-Wconversion",
"-Wsign-conversion",

At the beginning, I mentioned that warnings do not cause compilation to fail. We can enforce these warnings such that a warning will result in an unsuccessful compilation.

This is good programming practice.

In the tasks.json file, add the following flags before ${file}, one per line:

"-Werror",

Leave a Reply

Your email address will not be published. Required fields are marked *