Next: Pragma Weak_External, Previous: Pragma Volatile, Up: Implementation Defined Pragmas
pragma Warnings (On | Off); pragma Warnings (On | Off, LOCAL_NAME); pragma Warnings (static_string_EXPRESSION); pragma Warnings (On | Off, static_string_EXPRESSION);
Normally warnings are enabled, with the output being controlled by
the command line switch. Warnings (Off
) turns off generation of
warnings until a Warnings (On
) is encountered or the end of the
current unit. If generation of warnings is turned off using this
pragma, then no warning messages are output, regardless of the
setting of the command line switches.
The form with a single argument may be used as a configuration pragma.
If the LOCAL_NAME parameter is present, warnings are suppressed for
the specified entity. This suppression is effective from the point where
it occurs till the end of the extended scope of the variable (similar to
the scope of Suppress
).
The form with a single static_string_EXPRESSION argument provides more precise control over which warnings are active. The string is a list of letters specifying which warnings are to be activated and which deactivated. The code for these letters is the same as the string used in the command line switch controlling warnings. The following is a brief summary. For full details see Warning Message Control.
a turn on all optional warnings (except d h l .o) A turn off all optional warnings .a* turn on warnings for failing assertions .A turn off warnings for failing assertions b turn on warnings for bad fixed value (not multiple of small) B* turn off warnings for bad fixed value (not multiple of small) c turn on warnings for constant conditional C* turn off warnings for constant conditional .c turn on warnings for unrepped components .C* turn off warnings for unrepped components d turn on warnings for implicit dereference D* turn off warnings for implicit dereference e treat all warnings as errors f turn on warnings for unreferenced formal F* turn off warnings for unreferenced formal g* turn on warnings for unrecognized pragma G turn off warnings for unrecognized pragma h turn on warnings for hiding variable H* turn off warnings for hiding variable i* turn on warnings for implementation unit I turn off warnings for implementation unit j turn on warnings for obsolescent (annex J) feature J* turn off warnings for obsolescent (annex J) feature k turn on warnings on constant variable K* turn off warnings on constant variable l turn on warnings for missing elaboration pragma L* turn off warnings for missing elaboration pragma m turn on warnings for variable assigned but not read M* turn off warnings for variable assigned but not read n* normal warning mode (cancels -gnatws/-gnatwe) o* turn on warnings for address clause overlay O turn off warnings for address clause overlay .o turn on warnings for out parameters assigned but not read .O* turn off warnings for out parameters assigned but not read p turn on warnings for ineffective pragma Inline in frontend P* turn off warnings for ineffective pragma Inline in frontend q* turn on warnings for questionable missing parentheses Q turn off warnings for questionable missing parentheses r turn on warnings for redundant construct R* turn off warnings for redundant construct .r turn on warnings for object renaming function .R* turn off warnings for object renaming function s suppress all warnings t turn on warnings for tracking deleted code T* turn off warnings for tracking deleted code u turn on warnings for unused entity U* turn off warnings for unused entity v* turn on warnings for unassigned variable V turn off warnings for unassigned variable w* turn on warnings for wrong low bound assumption W turn off warnings for wrong low bound assumption x* turn on warnings for export/import X turn off warnings for export/import .x turn on warnings for non-local exceptions .X* turn off warnings for non-local exceptions y* turn on warnings for Ada 2005 incompatibility Y turn off warnings for Ada 2005 incompatibility z* turn on convention/size/align warnings for unchecked conversion Z turn off convention/size/align warnings for unchecked conversion * indicates default in above list
The specified warnings will be in effect until the end of the program or another pragma Warnings is encountered. The effect of the pragma is cumulative. Initially the set of warnings is the standard default set as possibly modified by compiler switches. Then each pragma Warning modifies this set of warnings as specified. This form of the pragma may also be used as a configuration pragma.
The fourth form, with an On|Off parameter and a string, is used to control individual messages, based on their text. The string argument is a pattern that is used to match against the text of individual warning messages (not including the initial "warnings: " tag).
The pattern may contain asterisks which match zero or more characters in
the message. For example, you can use
pragma Warnings (Off, "*bits of*unused")
to suppress the warning
message warning: 960 bits of "a" unused
. No other regular
expression notations are permitted. All characters other than asterisk in
these three specific cases are treated as literal characters in the match.
There are two ways to use this pragma. The OFF form can be used as a configuration pragma. The effect is to suppress all warnings (if any) that match the pattern string throughout the compilation.
The second usage is to suppress a warning locally, and in this case, two pragmas must appear in sequence:
pragma Warnings (Off, Pattern); ... code where given warning is to be suppressed pragma Warnings (On, Pattern);
In this usage, the pattern string must match in the Off and On pragmas, and at least one matching warning must be suppressed.