Next: , Up: Switches for gcc


3.2.1 Output and Error Message Control

The standard default format for error messages is called "brief format." Brief format messages are written to stderr (the standard error file) and have the following form:

     e.adb:3:04: Incorrect spelling of keyword "function"
     e.adb:4:20: ";" should be "is"

The first integer after the file name is the line number in the file, and the second integer is the column number within the line. glide can parse the error messages and point to the referenced character. The following switches provide control over the error message format:

-gnatv
The v stands for verbose. The effect of this setting is to write long-format error messages to stdout (the standard output file. The same program compiled with the -gnatv switch would generate:
          

3. funcion X (Q : Integer) | >>> Incorrect spelling of keyword "function" 4. return Integer; | >>> ";" should be "is"

The vertical bar indicates the location of the error, and the `>>>' prefix can be used to search for error messages. When this switch is used the only source lines output are those with errors.

-gnatl
The l stands for list. This switch causes a full listing of the file to be generated. The output might look as follows:
          

1. procedure E is 2. V : Integer; 3. funcion X (Q : Integer) | >>> Incorrect spelling of keyword "function" 4. return Integer; | >>> ";" should be "is" 5. begin 6. return Q + Q; 7. end; 8. begin 9. V := X + X; 10.end E;

When you specify the -gnatv or -gnatl switches and standard output is redirected, a brief summary is written to stderr (standard error) giving the number of error messages and warning messages generated.

-gnatU
This switch forces all error messages to be preceded by the unique string "error:". This means that error messages take a few more characters in space, but allows easy searching for and identification of error messages.
-gnatb
The b stands for brief. This switch causes GNAT to generate the brief format error messages to stderr (the standard error file) as well as the verbose format message or full listing (which as usual is written to stdout (the standard output file).
-gnatmn
The m stands for maximum. n is a decimal integer in the range of 1 to 999 and limits the number of error messages to be generated. For example, using -gnatm2 might yield
          e.adb:3:04: Incorrect spelling of keyword "function"
          e.adb:5:35: missing ".."
          fatal error: maximum errors reached
          compilation abandoned
     

-gnatf
The f stands for full. Normally, the compiler suppresses error messages that are likely to be redundant. This switch causes all error messages to be generated. In particular, in the case of references to undefined variables. If a given variable is referenced several times, the normal format of messages is
          e.adb:7:07: "V" is undefined (more references follow)
     

where the parenthetical comment warns that there are additional references to the variable V. Compiling the same program with the -gnatf switch yields

          e.adb:7:07: "V" is undefined
          e.adb:8:07: "V" is undefined
          e.adb:8:12: "V" is undefined
          e.adb:8:16: "V" is undefined
          e.adb:9:07: "V" is undefined
          e.adb:9:12: "V" is undefined
     

-gnatq
The q stands for quit (really "don't quit"). In normal operation mode, the compiler first parses the program and determines if there are any syntax errors. If there are, appropriate error messages are generated and compilation is immediately terminated. This switch tells GNAT to continue with semantic analysis even if syntax errors have been found. This may enable the detection of more errors in a single run. On the other hand, the semantic analyzer is more likely to encounter some internal fatal error when given a syntactically invalid tree.
-gnatQ
In normal operation mode, the ali file is not generated if any illegalities are detected in the program. The use of -gnatQ forces generation of the ali file. This file is marked as being in error, so it cannot be used for binding purposes, but it does contain reasonably complete cross-reference information, and thus may be useful for use by tools (e.g. semantic browsing tools or integrated development environments) that are driven from the ali file.

In addition, if -gnatt is also specified, then the tree file is generated even if there are illegalities. It may be useful in this case to also specify -gnatq to ensure that full semantic processing occurs. The resulting tree file can be processed by ASIS, for the purpose of providing partial information about illegal units, but if the error causes the tree to be badly malformed, then ASIS may crash during the analysis.

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, which is not necessarily complete.

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 -gnatwb (biased rounding), -gnatwd (implicit dereferencing), and -gnatwh (hiding). 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 biased rounding)
If a static floating-point expression has a value that is exactly half way between two adjacent machine numbers, then the rules of Ada (Ada Reference Manual, section 4.9(38)) require that this rounding be done away from zero, even if the normal unbiased rounding rules at run time would require rounding towards zero. This warning message alerts you to such instances where compile-time rounding and run-time rounding are not equivalent. If it is important to get proper run-time rounding, then you can force this by making one of the operands into a variable. The default is that such warnings are not generated. Note that -gnatwa does not affect the setting of this warning option.
-gnatwB (suppress warnings on biased rounding)
This switch disables warnings on biased rounding.
-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. 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 deferences 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.
-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.
-gnatwl (activate warnings on elaboration pragmas)
This switch activates warnings on missing pragma Elaborate_All statements. See the section in this guide on elaboration checking for details on when such pragma should be used. The default is that such warnings are not generated. This warning can also be turned on using -gnatwa.
-gnatwL (suppress warnings on elaboration pragmas)
This switch suppresses warnings on missing pragma Elaborate_All statements. See the section in this guide on elaboration checking for details on when such pragma should be used.
-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 defined 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 is 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).

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

          -gnatwaLe
     

Would turn on all optional warnings except for elaboration pragma warnings, and also specify that warnings should be treated as errors.

-w
This switch suppresses warnings from the gcc backend. It may be used in conjunction with -gnatws to ensure that all warnings are suppressed during the entire compilation process.