2.4 Options to request or suppress errors and warnings
Errors are diagnostic messages that report that the GNU Fortran compiler
cannot compile the relevant piece of source code. The compiler will
continue to process the program in an attempt to report further errors
to aid in debugging, but will not produce any compiled output.
Warnings are diagnostic messages that report constructions which
are not inherently erroneous but which are risky or suggest there is
likely to be a bug in the program. Unless -Werror is specified,
they do not prevent compilation of the program.
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 errors and warnings produced
by GNU Fortran:
- Limits the maximum number of error messages to n, at which point
GNU Fortran bails out rather than attempting to continue processing the
source code. If n is 0, there is no limit on the number of error
- Check the code for syntax errors, but do not actually compile it. This
will generate module files for each module present in the code, but no
other output file.
- Issue warnings for uses of extensions to Fortran 95.
-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
Valid Fortran 95 programs should compile properly with or without
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 conformance.
They soon find that it does not do quite what they want—it finds some
nonstandard practices, but not all.
However, improvements to GNU Fortran in this area are welcome.
This should be used in conjunction with -std=f95,
-std=f2003 or -std=f2008.
- Like -pedantic, except that errors are produced rather than
- Enables commonly used warning options pertaining to usage that
we recommend avoiding and that we believe are easy to avoid.
This currently includes -Waliasing, -Wampersand,
-Wconversion, -Wsurprising, -Wc-binding-type,
-Wintrinsics-std, -Wno-tabs, -Wintrinsic-shadow,
-Wreal-q-constant and -Wunused.
- Warn about possible aliasing of dummy arguments. Specifically, it warns
if the same actual argument is associated with a dummy argument with
INTENT(IN) and a dummy argument with
INTENT(OUT) in a call
with an explicit interface.
The following example will trigger the warning.
integer, intent(in) :: a
integer, intent(out) :: b
integer :: a
- Warn about missing ampersand in continued character constants. The warning is
given with -Wampersand, -pedantic, -std=f95,
-std=f2003 and -std=f2008. Note: With no ampersand
given in a continued character constant, GNU Fortran assumes continuation
at the first non-comment, non-whitespace character after the ampersand
that initiated the continuation.
- Warn about array temporaries generated by the compiler. The information
generated by this warning is sometimes useful in optimization, in order to
avoid such temporaries.
- Warn if the a variable might not be C interoperable. In particular, warn if
the variable has been declared using an intrinsic type with default kind
instead of using a kind parameter defined for C interoperability in the
ISO_C_Binding module. This option is implied by
- Warn when a character assignment will truncate the assigned string.
- Warn when a source code line will be truncated. This option is
implied by -Wall.
- Warn about implicit conversions that are likely to change the value of
the expression after conversion. Implied by -Wall.
- Warn about implicit conversions between different types and kinds.
- Enables some warning options for usages of language features which
may be problematic. This currently includes -Wcompare-reals
- Warn if a procedure is called without an explicit interface.
Note this only checks that an explicit interface is present. It does not
check that the declared interfaces are consistent across program units.
- Warn if a procedure is called that has neither an explicit interface
nor has been declared as
- Warn if gfortran finds a procedure named like an intrinsic not
available in the currently selected standard (with -std) and treats
EXTERNAL procedure because of this. -fall-intrinsics can
be used to never trigger this behavior and always link to the intrinsic
regardless of the selected standard.
- Produce a warning if a real-literal-constant contains a
- Produce a warning when “suspicious” code constructs are encountered.
While technically legal these usually indicate that an error has been made.
This currently produces a warning under the following circumstances:
- An INTEGER SELECT construct has a CASE that can never be matched as its
lower value is greater than its upper value.
- A LOGICAL SELECT construct has three CASE statements.
- A TRANSFER specifies a source that is shorter than the destination.
- The type of a function result is declared more than once with the same type. If
-pedantic or standard-conforming mode is enabled, this is an error.
CHARACTER variable is declared with negative length.
- By default, tabs are accepted as whitespace, but tabs are not members
of the Fortran Character Set. For continuation lines, a tab followed
by a digit between 1 and 9 is supported. -Wno-tabs will cause
a warning to be issued if a tab is encountered. Note, -Wno-tabs
is active for -pedantic, -std=f95, -std=f2003,
-std=f2008 and -Wall.
- Produce a warning when numerical constant expressions are
encountered, which yield an UNDERFLOW during compilation.
- Warn if a user-defined procedure or module procedure has the same name as an
intrinsic; in this case, an explicit interface or
INTRINSIC declaration might be needed to get calls later resolved to
the desired intrinsic/procedure. This option is implied by -Wall.
- Warn about unused dummy arguments. This option is implied by -Wall.
- Contrary to gcc's meaning of -Wunused-parameter,
gfortran's implementation of this option does not warn
about unused dummy arguments (see -Wunused-dummy-argument),
but about unused
PARAMETER values. -Wunused-parameter
is not included in -Wall but is implied by -Wall -Wextra.
- By default, gfortran warns about any occasion of variables being
padded for proper alignment inside a
COMMON block. This warning can be turned
off via -Wno-align-commons. See also -falign-commons.
- Warn if any calls to functions are eliminated by the optimizations
enabled by the -ffrontend-optimize option.
- Warn when the compiler might insert code to for allocation or reallocation of
an allocatable array variable of intrinsic type in intrinsic assignments. In
hot loops, the Fortran 2003 reallocation feature may reduce the performance.
If the array is already allocated with the correct shape, consider using a
whole-array array-spec (e.g.
(:,:,:)) for the variable on the left-hand
side to prevent the reallocation check. Note that in some cases the warning
is shown, even if the compiler will optimize reallocation checks away. For
instance, when the right-hand side contains the same variable multiplied by
a scalar. See also -frealloc-lhs.
- Warn when the compiler inserts code to for allocation or reallocation of an
allocatable variable; this includes scalars and derived types.
- Warn when comparing real or complex types for equality or inequality.
This option is implied by -Wextra.
- Warn if the pointer in a pointer assignment might be longer than the its
target. This option is implied by -Wall.
- Turns all warnings into errors.
See Options to Request or Suppress Errors and Warnings, for information on
more options offered by the GBE shared by gfortran, gcc
and other GNU compilers.
Some of these have no effect when compiling programs written in Fortran.