8.2 Compiler warnings

8.2.1 Use a standard warning set

As far as possible projects should use —warning_level=VERBOSE.

8.2.2 How to handle a warning

Before doing anything, make sure you understand exactly what the warning istelling you. If you're not positive why a warning is appearing, ask for help.

Once you understand the warning, attempt the following solutions in order:

  • First, fix it or work around it. Make a strong attempt to actuallyaddress the warning, or find another way to accomplish the task that avoidsthe situation entirely.
  • Otherwise, determine if it's a false alarm. If you are convinced thatthe warning is invalid and that the code is actually safe and correct, add acomment to convince the reader of this fact and apply the @suppressannotation.
  • Otherwise, leave a TODO comment. This is a last resort. If you dothis, do not suppress the warning. The warning should be visible untilit can be taken care of properly.

8.2.3 Suppress a warning at the narrowest reasonable scope

Warnings are suppressed at the narrowest reasonable scope, usually that of a single local variable or very small method. Often a variable or method is extracted for that reason alone.

Example

  1. /** @suppress {uselessCode} Unrecognized 'use asm' declaration */
  2. function fn() {
  3. 'use asm';
  4. return 0;
  5. }

Even a large number of suppressions in a class is still better than blinding theentire class to this type of warning.