2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
6 .. index:: options, warnings, options, errors, warnings, suppressing, messages, error, messages, warning, suppressing warnings
8 .. _error-and-warning-options:
10 Options to request or suppress errors and warnings
11 **************************************************
13 Errors are diagnostic messages that report that the GNU Fortran compiler
14 cannot compile the relevant piece of source code. The compiler will
15 continue to process the program in an attempt to report further errors
16 to aid in debugging, but will not produce any compiled output.
18 Warnings are diagnostic messages that report constructions which
19 are not inherently erroneous but which are risky or suggest there is
20 likely to be a bug in the program. Unless :option:`-Werror` is specified,
21 they do not prevent compilation of the program.
23 You can request many specific warnings with options beginning :option:`-W`,
24 for example :option:`-Wimplicit` to request warnings on implicit
25 declarations. Each of these specific warning options also has a
26 negative form beginning :option:`-Wno-` to turn off warnings;
27 for example, :option:`-Wno-implicit`. This manual lists only one of the
28 two forms, whichever is not the default.
30 These options control the amount and kinds of errors and warnings produced
33 .. index:: fmax-errors=n, errors, limiting
35 .. option:: -fmax-errors={n}
37 Limits the maximum number of error messages to :samp:`{n}`, at which point
38 GNU Fortran bails out rather than attempting to continue processing the
39 source code. If :samp:`{n}` is 0, there is no limit on the number of error
42 .. index:: fsyntax-only, syntax checking
44 .. option:: -fsyntax-only
46 Check the code for syntax errors, but do not actually compile it. This
47 will generate module files for each module present in the code, but no
50 .. index:: pedantic, Wpedantic
52 .. option:: -Wpedantic, -pedantic
54 Issue warnings for uses of extensions to Fortran.
55 :option:`-pedantic` also applies to C-language constructs where they
56 occur in GNU Fortran source files, such as use of :samp:`\\e` in a
57 character constant within a directive like ``#include``.
59 Valid Fortran programs should compile properly with or without
61 However, without this option, certain GNU extensions and traditional
62 Fortran features are supported as well.
63 With this option, many of them are rejected.
65 Some users try to use :option:`-pedantic` to check programs for conformance.
66 They soon find that it does not do quite what they want---it finds some
67 nonstandard practices, but not all.
68 However, improvements to GNU Fortran in this area are welcome.
70 This should be used in conjunction with :option:`-std=f95`,
71 :option:`-std=f2003`, :option:`-std=f2008` or :option:`-std=f2018`.
73 .. index:: pedantic-errors
75 .. option:: -pedantic-errors
77 Like :option:`-pedantic`, except that errors are produced rather than
80 .. index:: Wall, all warnings, warnings, all
84 Enables commonly used warning options pertaining to usage that
85 we recommend avoiding and that we believe are easy to avoid.
86 This currently includes :option:`-Waliasing`, :option:`-Wampersand`,
87 :option:`-Wconversion`, :option:`-Wsurprising`, :option:`-Wc-binding-type`,
88 :option:`-Wintrinsics-std`, :option:`-Wtabs`, :option:`-Wintrinsic-shadow`,
89 :option:`-Wline-truncation`, :option:`-Wtarget-lifetime`,
90 :option:`-Winteger-division`, :option:`-Wreal-q-constant`, :option:`-Wunused`
91 and :option:`-Wundefined-do-loop`.
93 .. index:: Waliasing, aliasing, warnings, aliasing
95 .. option:: -Waliasing
97 Warn about possible aliasing of dummy arguments. Specifically, it warns
98 if the same actual argument is associated with a dummy argument with
99 ``INTENT(IN)`` and a dummy argument with ``INTENT(OUT)`` in a call
100 with an explicit interface.
102 The following example will trigger the warning.
104 .. code-block:: fortran
108 integer, intent(in) :: a
109 integer, intent(out) :: b
116 .. index:: Wampersand, warnings, ampersand, &
118 .. option:: -Wampersand
120 Warn about missing ampersand in continued character constants. The
121 warning is given with :option:`-Wampersand`, :option:`-pedantic`,
122 :option:`-std=f95`, :option:`-std=f2003`, :option:`-std=f2008` and
123 :option:`-std=f2018`. Note: With no ampersand given in a continued
124 character constant, GNU Fortran assumes continuation at the first
125 non-comment, non-whitespace character after the ampersand that
126 initiated the continuation.
128 .. index:: Warray-temporaries, warnings, array temporaries
130 .. option:: -Warray-temporaries
132 Warn about array temporaries generated by the compiler. The information
133 generated by this warning is sometimes useful in optimization, in order to
134 avoid such temporaries.
136 .. index:: Wc-binding-type, warning, C binding type
138 .. option:: -Wc-binding-type
140 Warn if the a variable might not be C interoperable. In particular, warn if
141 the variable has been declared using an intrinsic type with default kind
142 instead of using a kind parameter defined for C interoperability in the
143 intrinsic ``ISO_C_Binding`` module. This option is implied by
146 .. index:: Wcharacter-truncation, warnings, character truncation
148 .. option:: -Wcharacter-truncation
150 Warn when a character assignment will truncate the assigned string.
152 .. index:: Wline-truncation, warnings, line truncation
154 .. option:: -Wline-truncation
156 Warn when a source code line will be truncated. This option is
157 implied by :option:`-Wall`. For free-form source code, the default is
158 :option:`-Werror=line-truncation` such that truncations are reported as
161 .. index:: Wconversion, warnings, conversion, conversion
163 .. option:: -Wconversion
165 Warn about implicit conversions that are likely to change the value of
166 the expression after conversion. Implied by :option:`-Wall`.
168 .. index:: Wconversion-extra, warnings, conversion, conversion
170 .. option:: -Wconversion-extra
172 Warn about implicit conversions between different types and kinds. This
173 option does *not* imply :option:`-Wconversion`.
175 .. index:: Wextra, extra warnings, warnings, extra
179 Enables some warning options for usages of language features which
180 may be problematic. This currently includes :option:`-Wcompare-reals`,
181 :option:`-Wunused-parameter` and :option:`-Wdo-subscript`.
183 .. index:: Wfrontend-loop-interchange, warnings, loop interchange, loop interchange, warning
185 .. option:: -Wfrontend-loop-interchange
187 Warn when using :option:`-ffrontend-loop-interchange` for performing loop
190 .. index:: Wimplicit-interface, warnings, implicit interface
192 .. option:: -Wimplicit-interface
194 Warn if a procedure is called without an explicit interface.
195 Note this only checks that an explicit interface is present. It does not
196 check that the declared interfaces are consistent across program units.
198 .. index:: Wimplicit-procedure, warnings, implicit procedure
200 .. option:: -Wimplicit-procedure
202 Warn if a procedure is called that has neither an explicit interface
203 nor has been declared as ``EXTERNAL``.
205 .. index:: Winteger-division, warnings, integer division, warnings, division of integers
207 .. option:: -Winteger-division
209 Warn if a constant integer division truncates its result.
210 As an example, 3/5 evaluates to 0.
212 .. index:: Wintrinsics-std, warnings, non-standard intrinsics, warnings, intrinsics of other standards
214 .. option:: -Wintrinsics-std
216 Warn if :command:`gfortran` finds a procedure named like an intrinsic not
217 available in the currently selected standard (with :option:`-std`) and treats
218 it as ``EXTERNAL`` procedure because of this. :option:`-fall-intrinsics` can
219 be used to never trigger this behavior and always link to the intrinsic
220 regardless of the selected standard.
222 .. index:: Woverwrite-recursive, warnings, overwrite recursive
224 .. option:: -Wno-overwrite-recursive
226 Do not warn when :option:`-fno-automatic` is used with :option:`-frecursive`. Recursion
227 will be broken if the relevant local variables do not have the attribute
228 ``AUTOMATIC`` explicitly declared. This option can be used to suppress the warning
229 when it is known that recursion is not broken. Useful for build environments that use
232 .. index:: Wreal-q-constant, warnings, q exponent-letter
234 .. option:: -Wreal-q-constant
236 Produce a warning if a real-literal-constant contains a ``q``
239 .. index:: Wsurprising, warnings, suspicious code
241 .. option:: -Wsurprising
243 Produce a warning when 'suspicious' code constructs are encountered.
244 While technically legal these usually indicate that an error has been made.
246 This currently produces a warning under the following circumstances:
248 * An INTEGER SELECT construct has a CASE that can never be matched as its
249 lower value is greater than its upper value.
251 * A LOGICAL SELECT construct has three CASE statements.
253 * A TRANSFER specifies a source that is shorter than the destination.
255 * The type of a function result is declared more than once with the same type. If
256 :option:`-pedantic` or standard-conforming mode is enabled, this is an error.
258 * A ``CHARACTER`` variable is declared with negative length.
260 * With :option:`-fopenmp`, for fixed-form source code, when an ``omx``
261 vendor-extension sentinel is encountered. (The equivalent ``ompx``,
262 used in free-form source code, is diagnosed by default.)
264 .. index:: Wtabs, warnings, tabs, tabulators
268 By default, tabs are accepted as whitespace, but tabs are not members
269 of the Fortran Character Set. For continuation lines, a tab followed
270 by a digit between 1 and 9 is supported. :option:`-Wtabs` will cause a
271 warning to be issued if a tab is encountered. Note, :option:`-Wtabs` is
272 active for :option:`-pedantic`, :option:`-std=f95`, :option:`-std=f2003`,
273 :option:`-std=f2008`, :option:`-std=f2018` and
276 .. index:: Wundefined-do-loop, warnings, undefined do loop
278 .. option:: -Wundefined-do-loop
280 Warn if a DO loop with step either 1 or -1 yields an underflow or an overflow
281 during iteration of an induction variable of the loop.
282 This option is implied by :option:`-Wall`.
284 .. index:: Wunderflow, warnings, underflow, underflow
286 .. option:: -Wunderflow
288 Produce a warning when numerical constant expressions are
289 encountered, which yield an UNDERFLOW during compilation. Enabled by default.
291 .. index:: Wintrinsic-shadow, warnings, intrinsic, intrinsic
293 .. option:: -Wintrinsic-shadow
295 Warn if a user-defined procedure or module procedure has the same name as an
296 intrinsic; in this case, an explicit interface or ``EXTERNAL`` or
297 ``INTRINSIC`` declaration might be needed to get calls later resolved to
298 the desired intrinsic/procedure. This option is implied by :option:`-Wall`.
300 .. index:: Wuse-without-only, warnings, use statements, intrinsic
302 .. option:: -Wuse-without-only
304 Warn if a ``USE`` statement has no ``ONLY`` qualifier and
305 thus implicitly imports all public entities of the used module.
307 .. index:: Wunused-dummy-argument, warnings, unused dummy argument, unused dummy argument, dummy argument, unused
309 .. option:: -Wunused-dummy-argument
311 Warn about unused dummy arguments. This option is implied by :option:`-Wall`.
313 .. index:: Wunused-parameter, warnings, unused parameter, unused parameter
315 .. option:: -Wunused-parameter
317 Contrary to :command:`gcc`'s meaning of :option:`-Wunused-parameter`,
318 :command:`gfortran`'s implementation of this option does not warn
319 about unused dummy arguments (see :option:`-Wunused-dummy-argument`),
320 but about unused ``PARAMETER`` values. :option:`-Wunused-parameter`
321 is implied by :option:`-Wextra` if also :option:`-Wunused` or
322 :option:`-Wall` is used.
324 .. index:: Walign-commons, warnings, alignment of COMMON blocks, alignment of COMMON blocks
326 .. option:: -Walign-commons
328 By default, :command:`gfortran` warns about any occasion of variables being
329 padded for proper alignment inside a ``COMMON`` block. This warning can be turned
330 off via :option:`-Wno-align-commons`. See also :option:`-falign-commons`.
332 .. index:: Wfunction-elimination, function elimination, warnings, function elimination
334 .. option:: -Wfunction-elimination
336 Warn if any calls to impure functions are eliminated by the optimizations
337 enabled by the :option:`-ffrontend-optimize` option.
338 This option is implied by :option:`-Wextra`.
340 .. index:: Wrealloc-lhs, Reallocate the LHS in assignments, notification
342 .. option:: -Wrealloc-lhs
344 Warn when the compiler might insert code to for allocation or reallocation of
345 an allocatable array variable of intrinsic type in intrinsic assignments. In
346 hot loops, the Fortran 2003 reallocation feature may reduce the performance.
347 If the array is already allocated with the correct shape, consider using a
348 whole-array array-spec (e.g. ``(:,:,:)``) for the variable on the left-hand
349 side to prevent the reallocation check. Note that in some cases the warning
350 is shown, even if the compiler will optimize reallocation checks away. For
351 instance, when the right-hand side contains the same variable multiplied by
352 a scalar. See also :option:`-frealloc-lhs`.
354 .. index:: Wrealloc-lhs-all
356 .. option:: -Wrealloc-lhs-all
358 Warn when the compiler inserts code to for allocation or reallocation of an
359 allocatable variable; this includes scalars and derived types.
361 .. index:: Wcompare-reals
363 .. option:: -Wcompare-reals
365 Warn when comparing real or complex types for equality or inequality.
366 This option is implied by :option:`-Wextra`.
368 .. index:: Wtargt-lifetime
370 .. option:: -Wtarget-lifetime
372 Warn if the pointer in a pointer assignment might be longer than the its
373 target. This option is implied by :option:`-Wall`.
377 .. option:: -Wzerotrip
379 Warn if a ``DO`` loop is known to execute zero times at compile
380 time. This option is implied by :option:`-Wall`.
382 .. index:: Wdo-subscript
384 .. option:: -Wdo-subscript
386 Warn if an array subscript inside a DO loop could lead to an
387 out-of-bounds access even if the compiler cannot prove that the
388 statement is actually executed, in cases like
390 .. code-block:: fortran
394 if (condition(i)) then
399 This option is implied by :option:`-Wextra`.
401 .. index:: Werror, warnings, to errors
405 Turns all warnings into errors.
407 See :ref:`gcc:warning-options`, for information on
408 more options offered by the GBE shared by :command:`gfortran`, :command:`gcc`
409 and other GNU compilers.
411 Some of these have no effect when compiling programs written in Fortran.