]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/fortran/doc/gfortran/gnu-fortran-command-options/options-to-request-or-suppress-errors-and-warnings.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / fortran / doc / gfortran / gnu-fortran-command-options / options-to-request-or-suppress-errors-and-warnings.rst
CommitLineData
c63539ff
ML
1..
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.
5
6.. index:: options, warnings, options, errors, warnings, suppressing, messages, error, messages, warning, suppressing warnings
7
8.. _error-and-warning-options:
9
10Options to request or suppress errors and warnings
11**************************************************
12
13Errors are diagnostic messages that report that the GNU Fortran compiler
14cannot compile the relevant piece of source code. The compiler will
15continue to process the program in an attempt to report further errors
16to aid in debugging, but will not produce any compiled output.
17
18Warnings are diagnostic messages that report constructions which
19are not inherently erroneous but which are risky or suggest there is
20likely to be a bug in the program. Unless :option:`-Werror` is specified,
21they do not prevent compilation of the program.
22
23You can request many specific warnings with options beginning :option:`-W`,
24for example :option:`-Wimplicit` to request warnings on implicit
25declarations. Each of these specific warning options also has a
26negative form beginning :option:`-Wno-` to turn off warnings;
27for example, :option:`-Wno-implicit`. This manual lists only one of the
28two forms, whichever is not the default.
29
30These options control the amount and kinds of errors and warnings produced
31by GNU Fortran:
32
33.. index:: fmax-errors=n, errors, limiting
34
35.. option:: -fmax-errors={n}
36
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
40 messages produced.
41
42.. index:: fsyntax-only, syntax checking
43
44.. option:: -fsyntax-only
45
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
48 other output file.
49
50.. index:: pedantic, Wpedantic
51
52.. option:: -Wpedantic, -pedantic
53
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``.
58
59 Valid Fortran programs should compile properly with or without
60 this option.
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.
64
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.
69
70 This should be used in conjunction with :option:`-std=f95`,
71 :option:`-std=f2003`, :option:`-std=f2008` or :option:`-std=f2018`.
72
73.. index:: pedantic-errors
74
75.. option:: -pedantic-errors
76
77 Like :option:`-pedantic`, except that errors are produced rather than
78 warnings.
79
80.. index:: Wall, all warnings, warnings, all
81
82.. option:: -Wall
83
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`.
92
93.. index:: Waliasing, aliasing, warnings, aliasing
94
95.. option:: -Waliasing
96
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.
101
102 The following example will trigger the warning.
103
104 .. code-block:: fortran
105
106 interface
107 subroutine bar(a,b)
108 integer, intent(in) :: a
109 integer, intent(out) :: b
110 end subroutine
111 end interface
112 integer :: a
113
114 call bar(a,a)
115
116.. index:: Wampersand, warnings, ampersand, &
117
118.. option:: -Wampersand
119
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.
127
128.. index:: Warray-temporaries, warnings, array temporaries
129
130.. option:: -Warray-temporaries
131
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.
135
136.. index:: Wc-binding-type, warning, C binding type
137
138.. option:: -Wc-binding-type
139
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
144 :option:`-Wall`.
145
146.. index:: Wcharacter-truncation, warnings, character truncation
147
148.. option:: -Wcharacter-truncation
149
150 Warn when a character assignment will truncate the assigned string.
151
152.. index:: Wline-truncation, warnings, line truncation
153
154.. option:: -Wline-truncation
155
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
159 error.
160
161.. index:: Wconversion, warnings, conversion, conversion
162
163.. option:: -Wconversion
164
165 Warn about implicit conversions that are likely to change the value of
166 the expression after conversion. Implied by :option:`-Wall`.
167
168.. index:: Wconversion-extra, warnings, conversion, conversion
169
170.. option:: -Wconversion-extra
171
172 Warn about implicit conversions between different types and kinds. This
173 option does *not* imply :option:`-Wconversion`.
174
175.. index:: Wextra, extra warnings, warnings, extra
176
177.. option:: -Wextra
178
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`.
182
183.. index:: Wfrontend-loop-interchange, warnings, loop interchange, loop interchange, warning
184
185.. option:: -Wfrontend-loop-interchange
186
187 Warn when using :option:`-ffrontend-loop-interchange` for performing loop
188 interchanges.
189
190.. index:: Wimplicit-interface, warnings, implicit interface
191
192.. option:: -Wimplicit-interface
193
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.
197
198.. index:: Wimplicit-procedure, warnings, implicit procedure
199
200.. option:: -Wimplicit-procedure
201
202 Warn if a procedure is called that has neither an explicit interface
203 nor has been declared as ``EXTERNAL``.
204
205.. index:: Winteger-division, warnings, integer division, warnings, division of integers
206
207.. option:: -Winteger-division
208
209 Warn if a constant integer division truncates its result.
210 As an example, 3/5 evaluates to 0.
211
212.. index:: Wintrinsics-std, warnings, non-standard intrinsics, warnings, intrinsics of other standards
213
214.. option:: -Wintrinsics-std
215
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.
221
222.. index:: Woverwrite-recursive, warnings, overwrite recursive
223
224.. option:: -Wno-overwrite-recursive
225
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
230 :option:`-Werror`.
231
232.. index:: Wreal-q-constant, warnings, q exponent-letter
233
234.. option:: -Wreal-q-constant
235
236 Produce a warning if a real-literal-constant contains a ``q``
237 exponent-letter.
238
239.. index:: Wsurprising, warnings, suspicious code
240
241.. option:: -Wsurprising
242
243 Produce a warning when 'suspicious' code constructs are encountered.
244 While technically legal these usually indicate that an error has been made.
245
246 This currently produces a warning under the following circumstances:
247
248 * An INTEGER SELECT construct has a CASE that can never be matched as its
249 lower value is greater than its upper value.
250
251 * A LOGICAL SELECT construct has three CASE statements.
252
253 * A TRANSFER specifies a source that is shorter than the destination.
254
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.
257
258 * A ``CHARACTER`` variable is declared with negative length.
259
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.)
263
264.. index:: Wtabs, warnings, tabs, tabulators
265
266.. option:: -Wtabs
267
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
274 :option:`-Wall`.
275
276.. index:: Wundefined-do-loop, warnings, undefined do loop
277
278.. option:: -Wundefined-do-loop
279
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`.
283
284.. index:: Wunderflow, warnings, underflow, underflow
285
286.. option:: -Wunderflow
287
288 Produce a warning when numerical constant expressions are
289 encountered, which yield an UNDERFLOW during compilation. Enabled by default.
290
291.. index:: Wintrinsic-shadow, warnings, intrinsic, intrinsic
292
293.. option:: -Wintrinsic-shadow
294
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`.
299
300.. index:: Wuse-without-only, warnings, use statements, intrinsic
301
302.. option:: -Wuse-without-only
303
304 Warn if a ``USE`` statement has no ``ONLY`` qualifier and
305 thus implicitly imports all public entities of the used module.
306
307.. index:: Wunused-dummy-argument, warnings, unused dummy argument, unused dummy argument, dummy argument, unused
308
309.. option:: -Wunused-dummy-argument
310
311 Warn about unused dummy arguments. This option is implied by :option:`-Wall`.
312
313.. index:: Wunused-parameter, warnings, unused parameter, unused parameter
314
315.. option:: -Wunused-parameter
316
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.
323
324.. index:: Walign-commons, warnings, alignment of COMMON blocks, alignment of COMMON blocks
325
326.. option:: -Walign-commons
327
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`.
331
332.. index:: Wfunction-elimination, function elimination, warnings, function elimination
333
334.. option:: -Wfunction-elimination
335
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`.
339
340.. index:: Wrealloc-lhs, Reallocate the LHS in assignments, notification
341
342.. option:: -Wrealloc-lhs
343
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`.
353
354.. index:: Wrealloc-lhs-all
355
356.. option:: -Wrealloc-lhs-all
357
358 Warn when the compiler inserts code to for allocation or reallocation of an
359 allocatable variable; this includes scalars and derived types.
360
361.. index:: Wcompare-reals
362
363.. option:: -Wcompare-reals
364
365 Warn when comparing real or complex types for equality or inequality.
366 This option is implied by :option:`-Wextra`.
367
368.. index:: Wtargt-lifetime
369
370.. option:: -Wtarget-lifetime
371
372 Warn if the pointer in a pointer assignment might be longer than the its
373 target. This option is implied by :option:`-Wall`.
374
375.. index:: Wzerotrip
376
377.. option:: -Wzerotrip
378
379 Warn if a ``DO`` loop is known to execute zero times at compile
380 time. This option is implied by :option:`-Wall`.
381
382.. index:: Wdo-subscript
383
384.. option:: -Wdo-subscript
385
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
389
390 .. code-block:: fortran
391
392 real a(3)
393 do i=1,4
394 if (condition(i)) then
395 a(i) = 1.2
396 end if
397 end do
398
399 This option is implied by :option:`-Wextra`.
400
401.. index:: Werror, warnings, to errors
402
403.. option:: -Werror
404
405 Turns all warnings into errors.
406
407See :ref:`gcc:warning-options`, for information on
408more options offered by the GBE shared by :command:`gfortran`, :command:`gcc`
409and other GNU compilers.
410
3ed1b4ce 411Some of these have no effect when compiling programs written in Fortran.