Customization of Compiler Diagnostics

Compiler Diagnostics have the following conflicting goals:

Emit all possible messages from the compiler to ensure that the user gets the maximum information about potential problems detected by the compiler.

Reduce the number of messages so that the user is not overwhelmed by the sheer magnitude of the warnings.

Eliminate or reduce the number of benign or misleading messages

The right balance for these conflicting goals is different for each specific situation. It varies on the basis of various criteria such as the size of the application, resources allotted to eliminate warnings by changing source code, total number of messages emitted, new code or port of existing code, and coding guidelines. The recommended model is to use options such as +wlint, +w64bit, and +w to enable the right level of warnings and then use options to disable specific warnings that are not of interest or are too noisy.

Each distinct type of diagnostic emitted by the compiler has a number associated with it. The user can control the emission of each diagnostic separately. This allows the user to focus on specific warnings by choice. The following options and pragmas allow warnings to be disabled, enabled or considered as errors:

+Warg1[,arg2,….,argn]

This option selectively suppresses any specified warning messages. arg1 through argn are valid compiler warning message numbers.

+Wwarg1[,arg2,..,argn]

This option selectively enables emission of compiler diagnostics that are not enabled by default. arg1 through argn are valid compiler warning message numbers.

+Wearg1[,arg2,..,argn]

This option selectively interprets any specified warning messages as errors. arg1 through argn must be valid compiler warning message numbers. This allows the user to enforce a policy to disallow specific warnings by forcing an error at compile time.

Conflicts between +W, +Ww and +We options are resolved based on their severity. +We is the highest and +W is the lowest.

+Wmacro:MACRONAME:d1,d2,...,dn

This option disables warning diagnostics d1,d2,...,dn in the expansion of macro MACRONAME. If -1is given as the warning number, then all warnings are suppressed. This option is not applicable to warning numbers greater than 20000. +Wmacro has higher priority than the other diagnostic- control command-line options that are applicable to the whole source. Diagnostic control pragmas take priority based on where they are placed.

+opts filename

All compiler options, can be consolidated in a single configuration file using the +opts option. This reduces the clutter on the command line and provides a single location to specify the customizations. Comment lines can also be inserted in the +opts configuration file.

Example

$ cat warnings_config

#change warning about use of undefined variable to error +We2549

#enable warning about redeclaration of variable

+Ww3348

7

Page 7
Image 7
HP C/aC++ for PA-RISC Software manual Customization of Compiler Diagnostics