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 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 section lists compiler switches that are available to control the handling of warning messages. It is also possible to exercise much finer control over what warnings are issued and suppressed using the GNAT pragma Warnings, See Pragma Warnings.

-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), -gnatwl (elaboration warnings), -gnatw.o (warn on values set by out parameters ignored) and -gnatwt (tracking of deleted conditional code). 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.
-gnatw.a
Activate warnings on failing assertions. This switch activates warnings for assertions where the compiler can tell at compile time that the assertion will fail. Note that this warning is given even if assertions are disabled. The default is that such warnings are generated.
-gnatw.A
Suppress warnings on failing assertions. This switch suppresses warnings for assertions where the compiler can tell at compile time that the assertion will fail.
-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.
-gnatw.b
Activate warnings on biased representation. This switch activates warnings when a size clause, value size clause, component clause, or component size clause forces the use of biased representation for an integer type (e.g. representing a range of 10..11 in a single bit by using 0/1 to represent 10/11). The default is that such warnings are generated.
-gnatw.B
Suppress warnings on biased representation. This switch suppresses warnings for representation clauses that force the use of biased representation.
-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 option also generates warnings if one or both tests is optimized away in a membership test for integer values if the result can be determined at compile time. Range tests on enumeration types are not included, since it is common for such tests to include an end point.

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.
-gnatw.c
Activate warnings on missing component clauses. This switch activates warnings for record components where a record representation clause is present and has component clauses for the majority, but not all, of the components. A warning is given for each component for which no component clause is present.

This warning can also be turned on using -gnatwa.

-gnatw.C
Suppress warnings on missing component clauses. This switch suppresses warnings for record components that are missing a component clause in the situation described above.
-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.
-gnatw.e
Activate every optional warning This switch activates all optional warnings, including those which are not activated by -gnatwa.
-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. The default is that these warnings are not generated.
-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. This warning is also turned on by the use of -gnatwa.

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. The default is that such warnings are not given. This warning can also be turned on using -gnatwa.
-gnatwK
Suppress warnings on variables that could be constants. This switch disables warnings on variables that could be declared constants.
-gnatwl
Activate warnings for 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. In dynamic elaboration mode, this switch generations warnings about the need to add elaboration pragmas. Note however, that if you blindly follow these warnings, and add Elaborate_All warnings wherever they are recommended, you basically end up with the equivalent of the static elaboration model, which may not be what you want for legacy code for which the static model does not work.

For the static model, the messages generated are labeled "info:" (for information messages). They are not warnings to add elaboration pragmas, merely informational messages showing what implicit elaboration pragmas have been added, for use in analyzing elaboration circularity problems.

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 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. The default is that these warnings are not given.
-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.
-gnatw.o
Activate warnings on modified but unreferenced out parameters. This switch activates warnings for variables that are modified by using them as actuals for a call to a procedure with an out mode formal, where the resulting assigned value is never read. It is applicable in the case where there is more than one out mode formal. If there is only one out mode formal, the warning is issued by default (controlled by -gnatwu). 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. The default is that these warnings are not given. Note that this warning is not included in -gnatwa, it must be activated explicitly.
-gnatw.O
Disable warnings on modified but unreferenced out parameters. This switch suppresses warnings for variables that are modified by using them as actuals for a call to a procedure with an out mode formal, where the resulting assigned value is never read.
-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. The default is that such warnings are not given. This warning can also be turned on using -gnatwa. Warnings on ineffective inlining by the gcc back-end can be activated separately, using the gcc switch -Winline.
-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.
-gnatw.p
Activate warnings on parameter ordering. This switch activates warnings for cases of suspicious parameter ordering when the list of arguments are all simple identifiers that match the names of the formals, but are in a different order. The warning is suppressed if any use of named parameter notation is used, so this is the appropriate way to suppress a false positive (and serves to emphasize that the "misordering" is deliberate). The default is that such warnings are not given. This warning can also be turned on using -gnatwa.
-gnatw.P
Suppress warnings on parameter ordering. This switch suppresses warnings on cases of suspicious parameter ordering.
-gnatwq
Activate warnings on questionable missing parentheses. This switch activates warnings for cases where parentheses are not used and the result is potential ambiguity from a readers point of view. For example (not a > b) when a and b are modular means ((not a) > b) and very likely the programmer intended (not (a > b)). Similarly (-x mod 5) means (-(x mod 5)) and quite likely ((-x) mod 5) was intended. In such situations it seems best to follow the rule of always parenthesizing to make the association clear, and this warning switch warns if such parentheses are not present. The default is that these warnings are given. This warning can also be turned on using -gnatwa.
-gnatwQ
Suppress warnings on questionable missing parentheses. This switch suppresses warnings for cases where the association is not clear and the use of parentheses is preferred.
-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. The default is that warnings for redundant constructs are not given.

-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.
-gnatwt
Activate warnings for tracking of deleted conditional code. This switch activates warnings for tracking of code in conditionals (IF and CASE statements) that is detected to be dead code which cannot be executed, and which is removed by the front end. This warning is off by default, and is not turned on by -gnatwa, it has to be turned on explicitly. This may be useful for detecting deactivated code in certified applications.
-gnatwT
Suppress warnings for tracking of deleted conditional code. This switch suppresses warnings for tracking of deleted conditional code.
-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. This warning can also be turned on using -gnatwa.
-gnatwV
Suppress warnings on unassigned variables. This switch suppresses warnings for access to variables which may not be properly initialized. For variables of a composite type, the warning can also be suppressed in Ada 2005 by using a default initialization with a box. For example, if Table is an array of records whose components are only partially uninitialized, then the following code:
             Tab : Table := (others => <>);
     

will suppress warnings on subsequent statements that access components of variable Tab.

-gnatww
Activate warnings on wrong low bound assumption. This switch activates warnings for indexing an unconstrained string parameter with a literal or S'Length. This is a case where the code is assuming that the low bound is one, which is in general not true (for example when a slice is passed). The default is that such warnings are generated. This warning can also be turned on using -gnatwa.
-gnatwW
Suppress warnings on wrong low bound assumption. This switch suppresses warnings for indexing an unconstrained string parameter with a literal or S'Length. Note that this warning can also be suppressed in a particular case by adding an assertion that the lower bound is 1, as shown in the following example.
             procedure K (S : String) is
                pragma Assert (S'First = 1);
                ...
     

-gnatw.w
Activate warnings on unnecessary Warnings Off pragmas This switch activates warnings for use of pragma Warnings (Off, entity where either the pragma is entirely useless (because it suppresses no warnings), or it could be replaced by pragma Unreferenced or pragma Unmodified.The default is that these warnings are not given. Note that this warning is not included in -gnatwa, it must be activated explicitly.
-gnatw.W
Suppress warnings on unnecessary Warnings Off pragmas This switch suppresses warnings for use of pragma Warnings (Off, entity.
-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. This warning can also be turned on using -gnatwa.
-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.
-gnatw.x
Activate warnings for No_Exception_Propagation mode. This switch activates warnings for exception usage when pragma Restrictions (No_Exception_Propagation) is in effect. Warnings are given for implicit or explicit exception raises which are not covered by a local handler, and for exception handlers which do not cover a local raise. The default is that these warnings are not given.
-gnatw.X
Disable warnings for No_Exception_Propagation mode. This switch disables warnings for exception usage when pragma Restrictions (No_Exception_Propagation) is in effect.
-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. This warning can also be turned on using -gnatwa.
-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.
-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. Warnings are also generated for subprogram pointers with different conventions, and, on VMS only, for data pointers with different conventions. This warning can also be turned on using -gnatwa.
-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 or conventions.
-Wunused
The warnings controlled by the -gnatw switch are generated by the front end of the compiler. The GCC back end can provide additional warnings and they are controlled by the -W switch. For example, -Wunused activates back end warnings for entities that are declared but not referenced.
-Wuninitialized
Similarly, -Wuninitialized activates the back end warning for uninitialized variables. This switch must be used in conjunction with an optimization level greater than zero.
-Wall
This switch enables all the above 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 activate them. The use of this switch also sets the default front end warning mode to -gnatwa, that is, most front end warnings activated as well.
-w
Conversely, this switch suppresses warnings from the GCC back end. 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