This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

Re: Problem with generic interfaces.


Dear Gunnar,


> I have started to get problems with my generic interfaces, with
> gfortran downloaded from
> ftp://ftp.equation.com/gcc/gcc-4.6-20101030-32.exe.
>
> I have come to the conclusion that the problem might be related to
> interfaces where I in the procedures have mixed a type and types
> extended from that type.
>
> My question is then, is the following code legal?

No, gfortran tells you:
gunnar.f90:9.37:

    module procedure testa_a, testa_b
                                     1
Error: Ambiguous interfaces 'testa_b' and 'testa_a' in generic
interface 'testa' at (1)
gunnar.f90:24.9:

 use test
         1
Fatal Error: Can't open module file 'test.mod' for reading at (1): No
such file or directory

ifort opines:
gunnar.f90(30): error #8032: Generic procedure reference has two or
more specific procedure with the same type/rank/keyword signature.
[TESTA]
   call testa(b)
--------^
compilation aborted for gunnar.f90 (code 1)

>
> (I can solve my problem by using type instead of class for my
> declarations in the subroutines.)
>

Indeed.  The ambiguity arises because instances of CLASS(a) can be of
CLASS(b).  Which of test_a and test_b should chosen in this case?

Cheers

Paul

> module test
> ?type a_type
> ? ? integer :: a
> ?end type a_type
> ?type,extends(a_type):: ?b_type
> ? ? integer :: b
> ?end type b_type
> ?interface testa
> ? ? module procedure testa_a, testa_b
> ?end interface
> contains
> ?subroutine testa_a(a)
> ? ?class(a_type) :: a
> ? ?a%a =1
> ?end subroutine testa_a
> ?subroutine testa_b(b)
> ? ?class(b_type) :: b
> ? ?b%a =1
> ? ?b%b =1
> ?end subroutine testa_b
> end module test
>
> module aa
> ?use test
> contains
> ?subroutine aaa(a,b)
> ? ?type(a_type) :: a
> ? ?type(b_type) :: b
> ? ?call testa(a)
> ? ?call testa(b)
> ?end subroutine aaa
> end module aa
>
> Regards,
>
> Gunnar
>


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