[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#844036: gfortran-6: spits out false warning about COMPLEX(4) to REAL(4) conversion when using a complex parameter



Package: gfortran-6
Version: 6.2.0-10
Severity: normal

Hello,
I think I found a bug in gfortran.

Please consider the following simple program:

  $ cat cpxparam.f 
        program main
  
        complex iu
        parameter (iu=(0,1))
  
        complex val1,val2
  
        write (*,*) 'iu = ',iu
  
        val1 = (+2.0,+3.0)
        val2 = (+4.0,-1.0)
  
  c     the following should write (2 + j3)/(j*(4 - j) = (14 - j*5)/17
  c     that is to say about  (0.8235294 , -0.2941176)
        write (*,*) val1/(iu*val2)
  
        end

If I try to compile this with the following command line:

  $ gfortran -pedantic -Wall -fimplicit-none -o cpxparam cpxparam.f
  cpxparam.f:4:20:
  
         parameter (iu=(0,1))
                      1
  Warning: Non-zero imaginary part discarded in conversion from ‘COMPLEX(4)’ to ‘REAL(4)’ at (1) [-Wconversion]

I get the above-quoted scary warning about an unintended conversion of
iu to real type!!!
But this conversion seems to never take place (luckily):

  $ ./cpxparam
   iu =  (  0.00000000    ,  1.00000000    )
   ( 0.823529422    ,-0.294117659    )

As you can see, the output is the expected one.

At first I thought a recent gfortran could maybe have some issues
in dealing with the old Fortran77-style syntax.
So, let's try with some more modern style:

  $ cat cpxparam_modern.f 
        program main
  
        complex,parameter :: iu=(0,1)
  
        complex :: val1,val2
  
        write (*,*) 'iu = ',iu
  
        val1 = (+2.0,+3.0)
        val2 = (+4.0,-1.0)
  
  c     the following should write (2 + j3)/(j*(4 - j) = (14 - j*5)/17
  c     that is to say about  (0.8235294 , -0.2941176)
        write (*,*) val1/(iu*val2)
  
        end

Same story:

  $ gfortran -pedantic -Wall -fimplicit-none -o cpxparam_modern cpxparam_modern.f 
  cpxparam_modern.f:3:30:
  
         complex,parameter :: iu=(0,1)
                                1
  Warning: Non-zero imaginary part discarded in conversion from ‘COMPLEX(4)’ to ‘REAL(4)’ at (1) [-Wconversion]
  $ ./cpxparam_modern 
   iu =  (  0.00000000    ,  1.00000000    )
   ( 0.823529422    ,-0.294117659    )

The scary warning is still produced and the executable output is still
correct, despite the compile-time warning.


Curiously, changing the last expression to be evaluated into a
different, but mathematically equivalent one makes the warning go
away:

  $ cat cpxparam2.f 
        program main
  
        complex iu
        parameter (iu=(0,1))
  
        complex val1,val2
  
        write (*,*) 'iu = ',iu
  
        val1 = (+2.0,+3.0)
        val2 = (+4.0,-1.0)
  
  c     the following should write (2 + j3)/(j*(4 - j) = (14 - j*5)/17
  c     that is to say about  (0.8235294 , -0.2941176)
        write (*,*) -iu*val1/val2
  
        end
  $ gfortran -pedantic -Wall -fimplicit-none -o cpxparam2 cpxparam2.f
  $ ./cpxparam2 
   iu =  (  0.00000000    ,  1.00000000    )
   ( 0.823529422    ,-0.294117659    )

No warning and correct output from the compiled program.


Please investigate this bug and/or forward my bug report upstream,
as appropriate.

Thanks for your time!
Bye.


P.S.: the above-quoted simple programs are probably trivial enough to
not be copyrighted; in case this turns out to be false, I hereby
release them under the terms of the Expat license
<http://www.jclark.com/xml/copying.txt>


-- System Information:
Debian Release: stretch/sid
  APT prefers testing
  APT policy: (800, 'testing'), (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 4.7.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages gfortran-6 depends on:
ii  gcc-6              6.2.0-10
ii  gcc-6-base         6.2.0-10
ii  libc6              2.24-5
ii  libc6-dev          2.24-5
ii  libgfortran-6-dev  6.2.0-10
ii  libgmp10           2:6.1.1+dfsg-1
ii  libisl15           0.17.1-1
ii  libmpc3            1.0.3-1
ii  libmpfr4           3.1.5-1
ii  zlib1g             1:1.2.8.dfsg-2+b3

gfortran-6 recommends no packages.

Versions of packages gfortran-6 suggests:
pn  gfortran-6-doc       <none>
pn  gfortran-6-multilib  <none>
pn  libcoarrays-dev      <none>
pn  libgfortran3-dbg     <none>

-- no debconf information


Reply to: