Next: Debugging and Assertion Control, Previous: Output and Error Message Control, Up: Compiler Switches
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 the description of the pragma in the GNAT_Reference_manual).
-gnatwa
This switch activates most optional warning messages. See the 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)
-gnatw.d
(tag warnings with -gnatw switch)
-gnatwh
(hiding)
-gnatw.h
(holes in record layouts)
-gnatw.k
(redefinition of names in standard)
-gnatwl
(elaboration warnings)
-gnatw.l
(inherited aspects)
-gnatw.n
(atomic synchronization)
-gnatwo
(address clause overlay)
-gnatw.o
(values set by out parameters ignored)
-gnatw.s
(overridden size clause)
-gnatwt
(tracking of deleted conditional code)
-gnatw.u
(unordered enumeration)
-gnatw.w
(use of Warnings Off)
-gnatw.y
(reasons for package needing body)
All other optional warnings are turned on.
-gnatwA
This switch suppresses all optional warning messages, see remaining list in this section for details on optional warning messages that can be individually controlled. Note that unlike switch `-gnatws', the use of switch `-gnatwA' does not suppress warnings that are normally given unconditionally and cannot be individually controlled (for example, the warning about a missing exit path in a function). Also, again unlike switch `-gnatws', warnings suppressed by the use of switch `-gnatwA' can be individually turned back on. For example the use of switch `-gnatwA' followed by switch `-gnatwd' will suppress all optional warnings except the warnings for implicit dereferencing.
-gnatw.a
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
This switch suppresses warnings for assertions where the compiler can tell at compile time that the assertion will fail.
-gnatwb
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
This switch suppresses warnings for static fixed-point expressions whose value is not an exact multiple of Small.
-gnatw.b
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
This switch suppresses warnings for representation clauses that force the use of biased representation.
-gnatwc
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
This switch suppresses warnings for conditional expressions used in tests that are known to be True or False at compile time.
-gnatw.c
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.
-gnatw.C
This switch suppresses warnings for record components that are missing a component clause in the situation described above.
-gnatwd
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.
-gnatwD
This switch suppresses warnings for implicit dereferences in indexed components, slices, and selected components.
-gnatw.d
If this switch is set, then warning messages are tagged, with one of the following strings:
- `[-gnatw?]' Used to tag warnings controlled by the switch `-gnatwx' where x is a letter a-z.
- `[-gnatw.?]' Used to tag warnings controlled by the switch `-gnatw.x' where x is a letter a-z.
- `[-gnatel]' Used to tag elaboration information (info) messages generated when the static model of elaboration is used and the `-gnatel' switch is set.
- `[restriction warning]' Used to tag warning messages for restriction violations, activated by use of the pragma `Restriction_Warnings'.
- `[warning-as-error]' Used to tag warning messages that have been converted to error messages by use of the pragma Warning_As_Error. Note that such warnings are prefixed by the string "error: " rather than "warning: ".
- `[enabled by default]' Used to tag all other warnings that are always given by default, unless warnings are completely suppressed using pragma `Warnings(Off)' or the switch `-gnatws'.
-gnatw.D
If this switch is set, then warning messages return to the default mode in which warnings and info messages are not tagged as described above for -gnatw.d.
-gnatwe
This switch causes warning messages and style check 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. Note that this is the only -gnatw switch that affects the handling of style check messages. Note also that this switch has no effect on info (information) messages, which are not treated as errors if this switch is present.
-gnatw.e
This switch activates all optional warnings, including those which are not activated by -gnatwa. The use of this switch is not recommended for normal use. If you turn this switch on, it is almost certain that you will get large numbers of useless warnings. The warnings that are excluded from -gnatwa are typically highly specialized warnings that are suitable for use only in code that has been specifically designed according to specialized coding rules.
-gnatwf
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 `-gnatwu'. The default is that these warnings are not generated.
-gnatwF
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
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. The default is that such warnings are issued (satisfying the Ada Reference Manual requirement that such warnings appear).
-gnatwG
This switch suppresses warnings for unrecognized pragmas.
-gnatw.g
This switch sets the warning categories that are used by the standard GNAT style. Currently this is equivalent to `-gnatwAao.sI.C.V.X' but more warnings may be added in the future without advanced notice.
-gnatwh
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.
-gnatwH
This switch suppresses warnings on hiding declarations.
-gnatw.h
This switch activates warnings on component clauses in record representation clauses that leave holes (gaps) in the record layout. If this warning option is active, then record representation clauses should specify a contiguous layout, adding unused fill fields if needed.
-gnatw.H
This switch suppresses warnings on component clauses in record representation clauses that leave holes (haps) in the record layout.
-gnatwi
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
-gnatwI
This switch disables warnings for a `with' of an internal GNAT implementation unit.
-gnatw.i
This switch enables a warning on statically detectable overlapping actuals in a subprogram call, when one of the actuals is an in-out parameter, and the types of the actuals are not by-copy types. This warning is off by default.
-gnatw.I
This switch disables warnings on overlapping actuals in a call..
-gnatwj
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), and pragma Interface_Name will be flagged since its function is replaced by pragma Import.
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
This switch disables warnings on use of obsolescent features.
-gnatwk
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.
-gnatwK
This switch disables warnings on variables that could be declared constants.
-gnatw.k
This switch activates warnings for declarations that declare a name that is defined in package Standard. Such declarations can be confusing, especially since the names in package Standard continue to be directly visible, meaning that use visibiliy on such redeclared names does not work as expected. Names of discriminants and components in records are not included in this check.
-gnatw.K
This switch activates warnings for declarations that declare a name that is defined in package Standard.
-gnatwl
This switch activates warnings for possible elaboration problems, including suspicious use of Elaborate pragmas, when using the static elaboration model, and possible situations that may raise Program_Error when using the dynamic elaboration model. See the section in this guide on elaboration checking for further details. The default is that such warnings are not generated.
-gnatwL
This switch suppresses warnings for possible elaboration problems.
-gnatw.l
This switch causes the compiler to list inherited invariants, preconditions, and postconditions from Type_Invariant'Class, Invariant'Class, Pre'Class, and Post'Class aspects. Also list inherited subtype predicates.
-gnatw.L
This switch suppresses listing of inherited aspects.
-gnatwm
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. The default is that these warnings are not given.
-gnatwM
This switch disables warnings for variables that are assigned or initialized, but never read.
-gnatw.m
This switch activates warnings for modulus values that seem suspicious. The cases caught are where the size is the same as the modulus (e.g. a modulus of 7 with a size of 7 bits), and modulus values of 32 or 64 with no size clause. The guess in both cases is that 2**x was intended rather than x. In addition expressions of the form 2*x for small x generate a warning (the almost certainly accurate guess being that 2**x was intended). The default is that these warnings are given.
-gnatw.M
This switch disables warnings for suspicious modulus values.
-gnatwn
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'.
-gnatw.n
This switch actives warnings when an access to an atomic variable requires the generation of atomic synchronization code. These warnings are off by default.
-gnatw.N
This switch suppresses warnings when an access to an atomic variable requires the generation of atomic synchronization code.
-gnatwo
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.
-gnatwO
This switch suppresses warnings on possibly unintended initialization effects of defining address clauses that cause one variable to overlap another.
-gnatw.o
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.
-gnatw.O
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
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. Warnings on ineffective inlining by the gcc back-end can be activated separately, using the gcc switch -Winline.
-gnatwP
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
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.
-gnatw.P
This switch suppresses warnings on cases of suspicious parameter ordering.
-gnatwq
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.
-gnatwQ
This switch suppresses warnings for cases where the association is not clear and the use of parentheses is preferred.
-gnatwr
This switch activates warnings for redundant constructs. The following is the current list of constructs regarded as redundant:
The default is that warnings for redundant constructs are not given.
-gnatwR
This switch suppresses warnings for redundant constructs.
-gnatw.r
This switch activates warnings for an object renaming that renames a function call, which is equivalent to a constant declaration (as opposed to renaming the function itself). The default is that these warnings are given.
-gnatw.R
This switch suppresses warnings for object renaming function.
-gnatws
This switch completely suppresses the output of all warning messages from the GNAT front end, including both warnings that can be controlled by switches described in this section, and those that are normally given unconditionally. The effect of this suppress action can only be cancelled by a subsequent use of the switch `-gnatwn'.
Note that switch `-gnatws' 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'. Also this switch has no effect on the handling of style check messages.
-gnatw.s
This switch activates warnings on component clauses in record representation clauses where the length given overrides that specified by an explicit size clause for the component type. A warning is similarly given in the array case if a specified component size overrides an explicit size clause for the array component type.
-gnatw.S
This switch suppresses warnings on component clauses in record representation clauses that override size clauses, and similar warnings when an array component size overrides a size clause.
-gnatwt
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. This may be useful for detecting deactivated code in certified applications.
-gnatwT
This switch suppresses warnings for tracking of deleted conditional code.
-gnatw.t
This switch activates warnings on suspicious contracts. This includes warnings on suspicious postconditions (whether a pragma Postcondition or a Post aspect in Ada 2012) and suspicious contract cases (pragma or aspect Contract_Cases). A function postcondition or contract case is suspicious when no postcondition or contract case for this function mentions the result of the function. A procedure postcondition or contract case is suspicious when it only refers to the pre-state of the procedure, because in that case it should rather be expressed as a precondition. This switch also controls warnings on suspicious cases of expressions typically found in contracts like quantified expressions and uses of Update attribute. The default is that such warnings are generated.
-gnatw.T
This switch suppresses warnings on suspicious contracts.
-gnatwu
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 a with'ed 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').
-gnatwU
This switch suppresses warnings for unused entities and packages. It also turns off warnings on unreferenced formals (and thus includes the effect of `-gnatwF').
-gnatw.u
This switch causes enumeration types to be considered as conceptually unordered, unless an explicit pragma Ordered is given for the type. The effect is to generate warnings in clients that use explicit comparisons or subranges, since these constructs both treat objects of the type as ordered. (A `client' is defined as a unit that is other than the unit in which the type is declared, or its body or subunits.) Please refer to the description of pragma Ordered in the GNAT Reference Manual for further details. The default is that such warnings are not generated.
-gnatw.U
This switch causes all enumeration types to be considered as ordered, so that no warnings are given for comparisons or subranges for any type.
-gnatwv
This switch activates warnings for access to variables which may not be properly initialized. The default is that such warnings are generated.
-gnatwV
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.
-gnatw.v
This switch activates messages (labeled "info", they are not warnings, just informational messages) about the effects of non-default bit-order on records to which a component clause is applied. The effect of specifying non-default bit ordering is a bit subtle (and changed with Ada 2005), so these messages, which are given by default, are useful in understanding the exact consequences of using this feature.
-gnatw.V
This switch suppresses information messages for the effects of specifying non-default bit order on record components with component clauses.
-gnatww
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.
-gnatwW
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
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. Also activates warnings for the case of Warnings (Off, String), where either there is no matching Warnings (On, String), or the Warnings (Off) did not suppress any warning. The default is that these warnings are not given.
-gnatw.W
This switch suppresses warnings for use of pragma Warnings (Off, ...).
-gnatwx
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
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
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
This switch disables warnings for exception usage when pragma Restrictions (No_Exception_Propagation) is in effect.
-gnatwy
For the most part, newer versions of Ada are upwards compatible with older versions. For example, Ada 2005 programs will almost always work when compiled as Ada 2012. However there are some exceptions (for example the fact that some is now a reserved word in Ada 2012). 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
This switch suppresses the warnings intended to help in identifying incompatibilities between Ada language versions.
-gnatw.y
There are a number of cases in which a package spec needs a body. For example, the use of pragma Elaborate_Body, or the declaration of a procedure specification requiring a completion. This switch causes information messages to be output showing why a package specification requires a body. This can be useful in the case of a large package specification which is unexpectedly requiring a body. The default is that such information messages are not output.
-gnatw.Y
This switch suppresses the output of information messages showing why a package specification needs a body.
-gnatwz
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.
-gnatwZ
This switch suppresses warnings for unchecked conversions where the types are known at compile time to have different sizes or conventions.
-gnatw.z
This switch activates warnings for cases of record types with specified Size and Alignment attributes where the size is not a multiple of the alignment, resulting in an object size that is greater than the specified size. The default is that such warnings are generated.
-gnatw.Z
This switch suppresses warnings for cases of record types with specified Size and Alignment attributes where the size is not a multiple of the alignment, resulting in an object size that is greater than the specified size. The warning can also be suppressed by giving an explicit Object_Size value.
-Wunused
-Wuninitialized
-Wstack-usage=`len'
-Wall
-w
-Werror
A string of warning parameters can be used in the same parameter. For example:
-gnatwaGe
will turn on all optional warnings except for unrecognized pragma warnings, and also specify that warnings should be treated as errors.
When no switch `-gnatw' is used, this is equivalent to:
-gnatw.a
-gnatwB
-gnatw.b
-gnatwC
-gnatw.C
-gnatwD
-gnatwF
-gnatwg
-gnatwH
-gnatwi
-gnatw.I
-gnatwJ
-gnatwK
-gnatwL
-gnatw.L
-gnatwM
-gnatw.m
-gnatwn
-gnatwo
-gnatw.O
-gnatwP
-gnatw.P
-gnatwq
-gnatwR
-gnatw.R
-gnatw.S
-gnatwT
-gnatw.T
-gnatwU
-gnatwv
-gnatww
-gnatw.W
-gnatwx
-gnatw.X
-gnatwy
-gnatwz