public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/35348]  New: g77 fails to warn critical real/complex assignment errors
@ 2008-02-24 10:03 ohyeahq at yahoo dot co dot jp
  2008-02-24 12:23 ` [Bug fortran/35348] " fxcoudert at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: ohyeahq at yahoo dot co dot jp @ 2008-02-24 10:03 UTC (permalink / raw)
  To: gcc-bugs

Dear Fortrunners:

The following code has two very common errors, but complies without errors or
warnings: (1) a complex-to-real assignment without explicit REALPART(); (2) a
subroutine call with an erroneous real-array arg in place of a complex-arrray
arg.  

      PROGRAM TESTCMPL
      IMPLICIT NONE
      REAL R,RA(2)
      COMPLEX C
      C=COMPLEX(1.0,1.0)
      R=C
      WRITE(*,*) 'C=',C,' -> R=',R
      RA(1)=1.0
      RA(2)=2.0
      WRITE(*,*) 'CALLS  AS:',RA(1),RA(2)
      CALL ARRAY(RA)
      STOP
      END

      SUBROUTINE ARRAY(CA)
      IMPLICIT NONE
      COMPLEX CA(2)
      WRITE(*,*) 'CALLED AS:',CA(1),CA(2)
      RETURN
      END

Here is the console output:

>g77 -mno-cygwin -O -fbounds-check -ftrapv -W -Wall -Wsurprising -pedantic -o testcmpl.exe testcmpl.f

>testcmpl

 C= (1.,1.) -> R=  1.
 CALLS  AS:  1.  2.
 CALLED AS: (1.,2.) (7.72198524E+033,1.)

g77 should give errors or warnings, because these errors are very common in
real life.  I suffered for one week locating these :-)

Cheeeeeers


-- 
           Summary: g77 fails to warn critical real/complex assignment
                    errors
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ohyeahq at yahoo dot co dot jp


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35348


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/35348] g77 fails to warn critical real/complex assignment errors
  2008-02-24 10:03 [Bug fortran/35348] New: g77 fails to warn critical real/complex assignment errors ohyeahq at yahoo dot co dot jp
@ 2008-02-24 12:23 ` fxcoudert at gcc dot gnu dot org
  2008-02-24 17:43 ` kargl at gcc dot gnu dot org
  2008-02-24 18:06 ` jvdelisle at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2008-02-24 12:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from fxcoudert at gcc dot gnu dot org  2008-02-24 12:22 -------
g77 is not supported any more; starting with GCC 4.0.0, it was replaced by
gfortran. Cygwin doesn't yet offer gfortran, so you'll have to ask them to do
so and/or download unofficial binaries from
http://gcc.gnu.org/wiki/GFortranBinaries.

For your problem: I think assignment of a complex value to a real variable is
valid Fortran, and behaves as you'd expect (assigning real part of the complex
value). The second issue is real, but hard to diagnose: it should be
incorporated in gfortran starting with 4.4.0, which is under development.


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fxcoudert at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35348


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/35348] g77 fails to warn critical real/complex assignment errors
  2008-02-24 10:03 [Bug fortran/35348] New: g77 fails to warn critical real/complex assignment errors ohyeahq at yahoo dot co dot jp
  2008-02-24 12:23 ` [Bug fortran/35348] " fxcoudert at gcc dot gnu dot org
@ 2008-02-24 17:43 ` kargl at gcc dot gnu dot org
  2008-02-24 18:06 ` jvdelisle at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: kargl at gcc dot gnu dot org @ 2008-02-24 17:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from kargl at gcc dot gnu dot org  2008-02-24 17:42 -------
FX is correct with respect to assignment of a complex expression
to a real variable.  See page 141 of the F2003 standard especially
table 7.9.

real x
complex :: z = (1,-1)
x = z
end 

The 'x = z' is treated as if you wrote 'x = real(z,kind(x))'

As to the subroutine problem, your program is technically
illegal for at least one reasone.  You've never assigned
a value to CA(2), so you're not allowed to reference it.

To avoid these types of issues if make the subroutine an
internal subprogram or use an explicit interface for the
subroutine.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35348


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/35348] g77 fails to warn critical real/complex assignment errors
  2008-02-24 10:03 [Bug fortran/35348] New: g77 fails to warn critical real/complex assignment errors ohyeahq at yahoo dot co dot jp
  2008-02-24 12:23 ` [Bug fortran/35348] " fxcoudert at gcc dot gnu dot org
  2008-02-24 17:43 ` kargl at gcc dot gnu dot org
@ 2008-02-24 18:06 ` jvdelisle at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-02-24 18:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jvdelisle at gcc dot gnu dot org  2008-02-24 18:05 -------
If you do decide to give gfortran a try from the binary you download at the
link given in comment #1, please let us know how it works for you.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35348


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-02-24 18:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-24 10:03 [Bug fortran/35348] New: g77 fails to warn critical real/complex assignment errors ohyeahq at yahoo dot co dot jp
2008-02-24 12:23 ` [Bug fortran/35348] " fxcoudert at gcc dot gnu dot org
2008-02-24 17:43 ` kargl at gcc dot gnu dot org
2008-02-24 18:06 ` jvdelisle at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).