F95 standard section 14.1.2.4.1 (particular Note 14.6) implies to me that when
an elemental and a non-elemental specific procedure in a generic interface both
"match" a reference, it is the specific instance that should be selected.

The reference selected by gfortran appears to depend on the ordering of
procedures in the generic interface block.  I'd expect the last line of output
from the following to be "S, S" as a result of selecting the specific procedure
"SpecProc".  I get "E, E" which has come from the elemental procedure.


MODULE SomeOptions
  IMPLICIT NONE  
  INTERFACE ElemSpec
    MODULE PROCEDURE ElemProc
    MODULE PROCEDURE SpecProc
  END INTERFACE ElemSpec  
  INTERFACE SpecElem
    MODULE PROCEDURE SpecProc
    MODULE PROCEDURE ElemProc
  END INTERFACE SpecElem
CONTAINS
  ELEMENTAL SUBROUTINE ElemProc(a)  
    CHARACTER, INTENT(OUT) :: a
    !****
    a = 'E'            
  END SUBROUTINE ElemProc

  SUBROUTINE SpecProc(a)  
    CHARACTER, INTENT(OUT) :: a(:)
    !****    
    a = 'S'    
  END SUBROUTINE SpecProc
END MODULE SomeOptions

PROGRAM MakeAChoice
  USE SomeOptions  
  IMPLICIT NONE
  CHARACTER scalar, array(2)    
  !****
  CALL ElemSpec(scalar) ! Should choose the elemental (and does)
  WRITE (*, 100) scalar
  CALL ElemSpec(array)  ! Should choose the specific (and does)
  WRITE (*, 100) array
  !----
  CALL SpecElem(scalar) ! Should choose the elemental (and does)
  WRITE (*, 100) scalar
  CALL SpecElem(array)  ! Should choose the specific (but doesn't)
  WRITE (*, 100) array  
  !----
  100 FORMAT(A,:,', ',A)
END PROGRAM MakeAChoice


>gfortran --version
GNU Fortran (GCC) 4.5.0 20090421 (experimental) [trunk revision 146519]


-- 
           Summary: Elemental procedure in genericl interface incorrectly
                    selected in preference to specific procedure
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ian_harvey at bigpond dot com
 GCC build triplet: i586-pc-mingw32
  GCC host triplet: i586-pc-mingw32
GCC target triplet: i586-pc-mingw32


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

Reply via email to