This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/27866] Warn when casting, e.g. assigning a double precision to a real
- From: "tkoenig at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Feb 2007 20:50:16 -0000
- Subject: [Bug fortran/27866] Warn when casting, e.g. assigning a double precision to a real
- References: <bug-27866-1719@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #4 from tkoenig at gcc dot gnu dot org 2007-02-16 20:50 -------
(In reply to comment #3)
> There is a new -Wconversion implementation. Perhaps you could do the same for
> fortran as I did for C/C++. Take a look at c-common.c (conversion_warnings). It
> would be great if -Wconversion behaves the same way (more or less) in all
> front-ends.
This would be a good idea.
Looking at the code from c-common.c, we should warn about
real(kind=4) :: a
real(kind=8) :: b
integer(kind=1) :: i1
integer(kind=4) :: i4
i4 = 2.3 ! Not exact
i1 = 500 ! doesn't fit
a = 2**26-1 ! Loses bits of precision
b = 1d99 ! Doesn't fit the type
a = i4 ! may lose extra digits
b = i4 ! This is OK (enough digits in the kind=8 var)
i1 = i4 ! i1 may not be able to represent the values in i4
a = b ! precision loss
For Fortran, we should also warn about
b = 2.5
print *,b**(3/2) ! identical to b**1, usually unintended
and maybe even about
print *,4/3 ! constant integer division
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27866