Next: , Previous: Output and Error Message Control, Up: Switches for gcc


3.2.2 Warning Message Control

In addition to error messages, which correspond to illegalities as defined in the Ada 95 Reference Manual, the compiler detects two kinds of warning situations.

First, the compiler considers some constructs suspicious and generates a warning message to alert you to a possible error. Second, if the compiler detects a situation that is sure to raise an exception at run time, it generates a warning message. The following shows an example of warning messages:

     e.adb:4:24: warning: creation of object may raise Storage_Error
     e.adb:10:17: warning: static value out of range
     e.adb:10:17: warning: "Constraint_Error" will be raised at run time

GNAT considers a large number of situations as appropriate for the generation of warning messages. As always, warnings are not definite indications of errors. For example, if you do an out-of-range assignment with the deliberate intention of raising a Constraint_Error exception, then the warning that may be issued does not indicate an error. Some of the situations for which GNAT issues warnings (at least some of the time) are given in the following list. This list is not complete, and new warnings are often added to subsequent versions of GNAT. The list is intended to give a general idea of the kinds of warnings that are generated.

The following switches are available to control the handling of warning messages:

-gnatwa
Activate all optional errors. This switch activates most optional warning messages, see remaining list in this section for details on optional warning messages that can be individually controlled. The warnings that are not turned on by this switch are -gnatwd (implicit dereferencing), -gnatwh (hiding), and -gnatwl (elaboration warnings). All other optional warnings are turned on.
-gnatwA
Suppress all optional errors. This switch suppresses all optional warning messages, see remaining list in this section for details on optional warning messages that can be individually controlled.
-gnatwb
Activate warnings on bad fixed values. This switch activates warnings for static fixed-point expressions whose value is not an exact multiple of Small. Such values are implementation dependent, since an implementation is free to choose either of the multiples that surround the value. GNAT always chooses the closer one, but this is not required behavior, and it is better to specify a value that is an exact multiple, ensuring predictable execution. The default is that such warnings are not generated.
-gnatwB
Suppress warnings on bad fixed values. This switch suppresses warnings for static fixed-point expressions whose value is not an exact multiple of Small.
-gnatwc
Activate warnings on conditionals. This switch activates warnings for conditional expressions used in tests that are known to be True or False at compile time. The default is that such warnings are not generated. Note that this warning does not get issued for the use of boolean variables or constants whose values are known at compile time, since this is a standard technique for conditional compilation in Ada, and this would generate too many “false positive” warnings.

This warning option also activates a special test for comparisons using the operators “>=” and“ <=”. If the compiler can tell that only the equality condition is possible, then it will warn that the “>” or “<” part of the test is useless and that the operator could be replaced by “=”. An example would be comparing a Natural variable <= 0.

This warning can also be turned on using -gnatwa.

-gnatwC
Suppress warnings on conditionals. This switch suppresses warnings for conditional expressions used in tests that are known to be True or False at compile time.
-gnatwd
Activate warnings on implicit dereferencing. If this switch is set, then the use of a prefix of an access type in an indexed component, slice, or selected component without an explicit .all will generate a warning. With this warning enabled, access checks occur only at points where an explicit .all appears in the source code (assuming no warnings are generated as a result of this switch). The default is that such warnings are not generated. Note that -gnatwa does not affect the setting of this warning option.
-gnatwD
Suppress warnings on implicit dereferencing. This switch suppresses warnings for implicit dereferences in indexed components, slices, and selected components.
-gnatwe
Treat warnings as errors. This switch causes warning messages to be treated as errors. The warning string still appears, but the warning messages are counted as errors, and prevent the generation of an object file.
-gnatwf
Activate warnings on unreferenced formals. This switch causes a warning to be generated if a formal parameter is not referenced in the body of the subprogram. This warning can also be turned on using -gnatwa or -gnatwu.
-gnatwF
Suppress warnings on unreferenced formals. This switch suppresses warnings for unreferenced formal parameters. Note that the combination -gnatwu followed by -gnatwF has the effect of warning on unreferenced entities other than subprogram formals.
-gnatwg
Activate warnings on unrecognized pragmas. This switch causes a warning to be generated if an unrecognized pragma is encountered. Apart from issuing this warning, the pragma is ignored and has no effect. This warning can also be turned on using -gnatwa. The default is that such warnings are issued (satisfying the Ada Reference Manual requirement that such warnings appear).
-gnatwG
Suppress warnings on unrecognized pragmas. This switch suppresses warnings for unrecognized pragmas.
-gnatwh
Activate warnings on hiding. This switch activates warnings on hiding declarations. A declaration is considered hiding if it is for a non-overloadable entity, and it declares an entity with the same name as some other entity that is directly or use-visible. The default is that such warnings are not generated. Note that -gnatwa does not affect the setting of this warning option.
-gnatwH
Suppress warnings on hiding. This switch suppresses warnings on hiding declarations.
-gnatwi
Activate warnings on implementation units. This switch activates warnings for a with of an internal GNAT implementation unit, defined as any unit from the Ada, Interfaces, GNAT, or System hierarchies that is not documented in either the Ada Reference Manual or the GNAT Programmer's Reference Manual. Such units are intended only for internal implementation purposes and should not be with'ed by user programs. The default is that such warnings are generated This warning can also be turned on using -gnatwa.
-gnatwI
Disable warnings on implementation units. This switch disables warnings for a with of an internal GNAT implementation unit.
-gnatwj
Activate warnings on obsolescent features (Annex J). If this warning option is activated, then warnings are generated for calls to subprograms marked with pragma Obsolescent and for use of features in Annex J of the Ada Reference Manual. In the case of Annex J, not all features are flagged. In particular use of the renamed packages (like Text_IO) and use of package ASCII are not flagged, since these are very common and would generate many annoying positive warnings. The default is that such warnings are not generated.

In addition to the above cases, warnings are also generated for GNAT features that have been provided in past versions but which have been superseded (typically by features in the new Ada standard). For example, pragma Ravenscar will be flagged since its function is replaced by pragma Profile(Ravenscar).

Note that this warning option functions differently from the restriction No_Obsolescent_Features in two respects. First, the restriction applies only to annex J features. Second, the restriction does flag uses of package ASCII.

-gnatwJ
Suppress warnings on obsolescent features (Annex J). This switch disables warnings on use of obsolescent features.
-gnatwk
Activate warnings on variables that could be constants. This switch activates warnings for variables that are initialized but never modified, and then could be declared constants.
-gnatwK
Suppress warnings on variables that could be constants. This switch disables warnings on variables that could be declared constants.
-gnatwl
Activate warnings for missing elaboration pragmas. This switch activates warnings on missing Elaborate_All and Elaborate pragmas. See the section in this guide on elaboration checking for details on when such pragmas should be used. Warnings are also generated if you are using the static mode of elaboration, and a pragma Elaborate is encountered. The default is that such warnings are not generated. This warning is not automatically turned on by the use of -gnatwa.
-gnatwL
Suppress warnings for missing elaboration pragmas. This switch suppresses warnings on missing Elaborate and Elaborate_All pragmas. See the section in this guide on elaboration checking for details on when such pragmas should be used.
-gnatwm
Activate warnings on modified but unreferenced variables. This switch activates warnings for variables that are assigned (using an initialization value or with one or more assignment statements) but whose value is never read. The warning is suppressed for volatile variables and also for variables that are renamings of other variables or for which an address clause is given. This warning can also be turned on using -gnatwa.
-gnatwM
Disable warnings on modified but unreferenced variables. This switch disables warnings for variables that are assigned or initialized, but never read.
-gnatwn
Set normal warnings mode. This switch sets normal warning mode, in which enabled warnings are issued and treated as warnings rather than errors. This is the default mode. the switch -gnatwn can be used to cancel the effect of an explicit -gnatws or -gnatwe. It also cancels the effect of the implicit -gnatwe that is activated by the use of -gnatg.
-gnatwo
Activate warnings on address clause overlays. This switch activates warnings for possibly unintended initialization effects of defining address clauses that cause one variable to overlap another. The default is that such warnings are generated. This warning can also be turned on using -gnatwa.
-gnatwO
Suppress warnings on address clause overlays. This switch suppresses warnings on possibly unintended initialization effects of defining address clauses that cause one variable to overlap another.
-gnatwp
Activate warnings on ineffective pragma Inlines. This switch activates warnings for failure of front end inlining (activated by -gnatN) to inline a particular call. There are many reasons for not being able to inline a call, including most commonly that the call is too complex to inline. This warning can also be turned on using -gnatwa.
-gnatwP
Suppress warnings on ineffective pragma Inlines. This switch suppresses warnings on ineffective pragma Inlines. If the inlining mechanism cannot inline a call, it will simply ignore the request silently.
-gnatwr
Activate warnings on redundant constructs. This switch activates warnings for redundant constructs. The following is the current list of constructs regarded as redundant: This warning can also be turned on using -gnatwa.
-gnatwR
Suppress warnings on redundant constructs. This switch suppresses warnings for redundant constructs.
-gnatws
Suppress all warnings. This switch completely suppresses the output of all warning messages from the GNAT front end. Note that it does not suppress warnings from the gcc back end. To suppress these back end warnings as well, use the switch -w in addition to -gnatws.
-gnatwu
Activate warnings on unused entities. This switch activates warnings to be generated for entities that are declared but not referenced, and for units that are with'ed and not referenced. In the case of packages, a warning is also generated if no entities in the package are referenced. This means that if the package is referenced but the only references are in use clauses or renames declarations, a warning is still generated. A warning is also generated for a generic package that is with'ed but never instantiated. In the case where a package or subprogram body is compiled, and there is a with on the corresponding spec that is only referenced in the body, a warning is also generated, noting that the with can be moved to the body. The default is that such warnings are not generated. This switch also activates warnings on unreferenced formals (it includes the effect of -gnatwf). This warning can also be turned on using -gnatwa.
-gnatwU
Suppress warnings on unused entities. This switch suppresses warnings for unused entities and packages. It also turns off warnings on unreferenced formals (and thus includes the effect of -gnatwF).
-gnatwv
Activate warnings on unassigned variables. This switch activates warnings for access to variables which may not be properly initialized. The default is that such warnings are generated.
-gnatwV
Suppress warnings on unassigned variables. This switch suppresses warnings for access to variables which may not be properly initialized.
-gnatwy
Activate warnings for Ada 2005 compatibility issues. For the most part Ada 2005 is upwards compatible with Ada 95, but there are some exceptions (for example the fact that interface is now a reserved word in Ada 2005). This switch activates several warnings to help in identifying and correcting such incompatibilities. The default is that these warnings are generated. Note that at one point Ada 2005 was called Ada 0Y, hence the choice of character.
-gnatwY
Disable warnings for Ada 2005 compatibility issues. This switch suppresses several warnings intended to help in identifying incompatibilities between Ada 95 and Ada 2005.
-gnatwx
Activate warnings on Export/Import pragmas. This switch activates warnings on Export/Import pragmas when the compiler detects a possible conflict between the Ada and foreign language calling sequences. For example, the use of default parameters in a convention C procedure is dubious because the C compiler cannot supply the proper default, so a warning is issued. The default is that such warnings are generated.
-gnatwX
Suppress warnings on Export/Import pragmas. This switch suppresses warnings on Export/Import pragmas. The sense of this is that you are telling the compiler that you know what you are doing in writing the pragma, and it should not complain at you.
-gnatwz
Activate warnings on unchecked conversions. This switch activates warnings for unchecked conversions where the types are known at compile time to have different sizes. The default is that such warnings are generated.
-gnatwZ
Suppress warnings on unchecked conversions. This switch suppresses warnings for unchecked conversions where the types are known at compile time to have different sizes.
-Wuninitialized
The warnings controlled by the -gnatw switch are generated by the front end of the compiler. In some cases, the gcc back end can provide additional warnings. One such useful warning is provided by -Wuninitialized. This must be used in conjunction with turning on optimization mode. This causes the flow analysis circuits of the back end optimizer to output additional warnings about uninitialized variables.
-w
This switch suppresses warnings from the gcc back end. The code generator detects a number of warning situations that are missed by the GNAT front end, and this switch can be used to suppress them. The use of this switch also sets the default front end warning mode to -gnatws, that is, front end warnings suppressed as well.

A string of warning parameters can be used in the same parameter. For example:

     -gnatwaLe

will turn on all optional warnings except for elaboration pragma warnings, and also specify that warnings should be treated as errors. When no switch -gnatw is used, this is equivalent to:

-gnatwC
-gnatwD
-gnatwF
-gnatwg
-gnatwH
-gnatwi
-gnatwJ
-gnatwK
-gnatwL
-gnatwM
-gnatwn
-gnatwo
-gnatwP
-gnatwR
-gnatwU
-gnatwv
-gnatwz
-gnatwx