[patch, fortran] PR 47359 - warnings for constant conversion
Thomas Koenig
tkoenig@netcologne.de
Sun May 31 21:36:00 GMT 2015
Hello world,
please find attached a rather lengthy patch, which attempts to deal
with warnings for conversions in Fortran once and for all (one can
hope ... :-)
The patch has two parts.
One part moves all the checking for conversion into the
gfc_<type>2<type> functions. The checks are made much more
extensive; for example, integer conversions to real are also
checked because they can change the value.
There is one change in behavior: Previosly, when a value
which did not change on a narrowing conversion was detected
with -Wconversion, it was not reported with -Wconversion-extra,
but there was a warning if only -Wconversion-extra was specified.
This patch changes that behavior so that -Wconversion and
-Wconversion-extra emit the same warning if the value is changed,
but that -Wconversion-extra, if specified alone, will emit
a warning anyway.
The second part catches the case when the user supplies more
digits than appropriate for the number. More often than not,
this is a KIND error.
For the second part (which can also be committed separately)
I am not sure if the -Wconversion-extra flag is the right one.
I shied away from specifying YANF (Yet Another New Flag), but
I could do so if the consensus is that this is better. It
might also be possible to invent another name for this option,
and maybe enable this with -Wsurprising.
Regression-tested. Comments? OK for trunk?
Thomas
2015-05-31 Thomas Koenig <tkoenig@netcologne.de>
PR fortran/47359
* arith.c (eval_intrinsic_op): Set warn flag for
gfc_type_convert_binary if -Wconversion or -Wconversion-extra
are set.
(wprecision_real_real): New function.
(wprecision_int_real): New function.
(gfc_int2int): If -fno-range-check and -Wconversion are specified
and it is a narrowing conversion, warn.
(gfc_int2real): If there is a change in value for the conversion,
warn.
(gfc_int2complex): Likewise.
(gfc_real2int): If there is a fractional part to the real number,
warn with -Wconversion, otherwise warn with -Wconversion-extra.
(gfc_real2real): Emit warning if the constant was changed by
conversion with either -Wconversion or -Wconversion-extra. With
-Wconversion-extra, warn if no warning was issued earlier.
(gfc_real2complex): Likewise.
(gfc_complex2int): For -Wconversion or -Wconversion-extra, if
there was an imaginary part, warn; otherwise, warn for change in
value. Warn with -Wconversion-extra if no other warning was
issued.
(gfc_complex2real): For -Wconversion or -Wconversion-extra, if
there was an imaginary part, warn; otherwise, warn for change in
value. Warn with -Wconversion-extra if no other warning was
issued.
(gfc_complex2complex): For -Wconversion, warn if the value of
either the real or the imaginary part was changed. Warn for
-Wconversion-extra if no prior warning was issued.
* expr.c (gfc_check_assign): Remove check for change in value.
* primary.c (match_real_constant): For -Wconversion-extra, check
against a number in which the last non-zero digit has been
replaced with a zero. If the number compares equal, warn.
2015-05-31 Thomas Koenig <tkoenig@netcologne.de>
PR fortran/47359
* gfortran.dg/array_constructor_type_17.f03: Adjust error message.
* gfortran.dg/warn_conversion.f90: Add warning for change in value
for assignment.
* gfortran.dg/warn_conversion_3.f90: Add warnings.
* gfortran.dg/warn_conversion_5.f90: New test.
* gfortran.dg/warn_conversion_6.f90: New test.
* gfortran.dg/warn_conversion_7.f90: New test.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: warn_conversion_5.f90
Type: text/x-fortran
Size: 1559 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20150531/70cb032f/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: warn_conversion_6.f90
Type: text/x-fortran
Size: 834 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20150531/70cb032f/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: warn_conversion_7.f90
Type: text/x-fortran
Size: 262 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20150531/70cb032f/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p12.diff
Type: text/x-patch
Size: 17710 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20150531/70cb032f/attachment-0003.bin>
More information about the Fortran
mailing list