This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/33542] New: gfortran does not detect ambigious specific names if they are the same as generic names


Found at
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/1abc1549a6a164f1/

One should re-check it as only g95 and Portland reject it whereas Pathscale,
gfortran, ifort, sunf95,openf95 and especially NAG f95 and Lahey accept it.

The following program is obviously wrong as one tries to pass an generic name
as actual argument, which is not possible as only specific names are allow.
gfortran and the other compilers properly diagnose:

Error: GENERIC non-INTRINSIC procedure 'foo' is not allowed as an actual
argument at (1)

for the following program:

MODULE M1
   INTERFACE FOO
     MODULE PROCEDURE FOO2
   END INTERFACE
CONTAINS
   SUBROUTINE FOO2(I)
     INTEGER, INTENT(IN) :: I
     WRITE(*,*) 'INTEGER'
   END SUBROUTINE FOO2
END MODULE M1

MODULE M2
   INTERFACE FOO
     MODULE PROCEDURE FOO2
   END INTERFACE
CONTAINS
   SUBROUTINE FOO2(R)
     REAL, INTENT(IN) :: R
     WRITE(*,*) 'REAL'
   END SUBROUTINE FOO2
END MODULE M2

PROGRAM P
   USE M1
   USE M2
   implicit none
   external bar
   CALL FOO(10)
   CALL FOO(10.)
   CALL BAR(foo) ! <<<< error needs specific interface
END PROGRAM P

The fun starts if the generic interface FOO has the same name as the specific
interfaces in each of the modules. Most compilers allow now this code although
it is ambiguous: Which of the two specific functions has to be used as actual
argument?

g95 and Portland reject the program as soon as any "foo" is used; the real
ambiguity is, however, only the FOO in "call BAR". Though probably any usage of
FOO should be rejected. (We need to check this carefully.)

Example, rejected by g95 and Portland, accepted by gfortran, NAG f95 etc.:

MODULE M1
   INTERFACE FOO
     MODULE PROCEDURE FOO
   END INTERFACE
CONTAINS
   SUBROUTINE FOO(I)
     INTEGER, INTENT(IN) :: I
     WRITE(*,*) 'INTEGER'
   END SUBROUTINE FOO
END MODULE M1

MODULE M2
   INTERFACE FOO
     MODULE PROCEDURE FOO
   END INTERFACE
CONTAINS
   SUBROUTINE FOO(R)
     REAL, INTENT(IN) :: R
     WRITE(*,*) 'REAL'
   END SUBROUTINE FOO
END MODULE M2

PROGRAM P
   USE M1
   USE M2
   implicit none
   external bar
   CALL FOO(10)
   CALL FOO(10.)
   CALL BAR(foo)
END PROGRAM P


-- 
           Summary: gfortran does not detect ambigious specific names if
                    they are the same as generic names
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]