Next: , Previous: Fortran Dialect Options, Up: Invoking G77

5.5 Options to Request or Suppress Warnings

Warnings are diagnostic messages that report constructions which are not inherently erroneous but which are risky or suggest there might have been an error.

You can request many specific warnings with options beginning -W, for example -Wimplicit to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning -Wno- to turn off warnings; for example, -Wno-implicit. This manual lists only one of the two forms, whichever is not the default.

These options control the amount and kinds of warnings produced by GNU Fortran:

Check the code for syntax errors, but don't do anything beyond that.

Issue warnings for uses of extensions to ANSI FORTRAN 77. -pedantic also applies to C-language constructs where they occur in GNU Fortran source files, such as use of `\e' in a character constant within a directive like `#include'.

Valid ANSI FORTRAN 77 programs should compile properly with or without this option. However, without this option, certain GNU extensions and traditional Fortran features are supported as well. With this option, many of them are rejected.

Some users try to use -pedantic to check programs for strict ANSI conformance. They soon find that it does not do quite what they want—it finds some non-ANSI practices, but not all. However, improvements to g77 in this area are welcome.

Like -pedantic, except that errors are produced rather than warnings.

Like -pedantic, but applies only to Fortran constructs.

Inhibit all warning messages.

Inhibit warnings about use of a name as both a global name (a subroutine, function, or block data program unit, or a common block) and implicitly as the name of an intrinsic in a source file.

Also inhibit warnings about inconsistent invocations and/or definitions of global procedures (function and subroutines). Such inconsistencies include different numbers of arguments and different types of arguments.

Warn whenever a variable, array, or function is implicitly declared. Has an effect similar to using the IMPLICIT NONE statement in every program unit. (Some Fortran compilers provide this feature by an option named -u or `/WARNINGS=DECLARATIONS'.)

Warn whenever a variable is unused aside from its declaration.

Warn whenever an automatic variable is used without first being initialized.

These warnings are possible only in optimizing compilation, because they require data-flow information that is computed only when optimizing. If you don't specify -O, you simply won't get these warnings.

These warnings occur only for variables that are candidates for register allocation. Therefore, they do not occur for a variable whose address is taken, or whose size is other than 1, 2, 4 or 8 bytes. Also, they do not occur for arrays, even when they are in registers.

Note that there might be no warning about a variable that is used only to compute a value that itself is never used, because such computations may be deleted by data-flow analysis before the warnings are printed.

These warnings are made optional because GNU Fortran is not smart enough to see all the reasons why the code might be correct despite appearing to have an error. Here is one example of how this can happen:

          IF (J.EQ.1) I=1
          IF (J.EQ.2) I=4
          IF (J.EQ.3) I=5
          CALL FOO(I)

If the value of J is always 1, 2 or 3, then I is always initialized, but GNU Fortran doesn't know this. Here is another common case:

          LOGICAL FLAG
          IF (FLAG) VALUE = 9.4
          IF (FLAG) PRINT *, VALUE

This has no bug because VALUE is used only if it is set.

The -Wunused and -Wuninitialized options combined. These are all the options which pertain to usage that we recommend avoiding and that we believe is easy to avoid. (As more warnings are added to g77 some might be added to the list enabled by -Wall.)

The remaining -W... options are not implied by -Wall because they warn about constructions that we consider reasonable to use, on occasion, in clean programs.

Warn about “suspicious” constructs that are interpreted by the compiler in a way that might well be surprising to someone reading the code. These differences can result in subtle, compiler-dependent (even machine-dependent) behavioral differences. The constructs warned about include:

Make all warnings into errors.

Turns on “extra warnings” and, if optimization is specified via -O, the -Wuninitialized option. (This might change in future versions of g77

“Extra warnings” are issued for:

See Options to Request or Suppress Warnings, for information on more options offered by the GBE shared by g77 gcc and other GNU compilers.

Some of these have no effect when compiling programs written in Fortran:













These options all could have some relevant meaning for GNU Fortran programs, but are not yet supported.