Select type selector question
- From: Paul Thomas <paul.richard.thomas@xxxxxxxxx>
- Date: Wed, 2 May 2012 04:34:57 -0700 (PDT)
Dear All,
What is a processor supposed to do with the following testcase?
implicit none
type t0
integer :: j = 42
end type t0
type, extends(t0) :: t1
integer :: k = 99
end type t1
type t
integer :: i
class(t0), allocatable :: foo
end type t
type(t) :: m(4)
integer :: n
do n = 1, 2
allocate(m(n)%foo, source = t0(n*99))
end do
do n = 3, 4
allocate(m(n)%foo, source = t1(n*99, n*999))
end do
! The class components 'foo' of m(1:2) now have a different dynamic
type to those of m(3:4)
select type(bar => m%foo) ! Should the processor throw an error here?
if not, what?
type is(t0)
if (any (bar%j .ne. [99, 198, 297, 396])) call abort
type is(t1)
call abort
end select
end
Perhaps I did not try hard enough but I was unable to find any
guidance in the standard as to what should happen. Several
possibilities come to mind:
(i) The compiler should throw the error since the ultimate components
might have different dynamic types;
(ii) A runtime check could be done, which throws an error if the
dynamic types are different;
(iii) The associate name reverts in this case to the declared type; or
............
Thanks in advance for any thoughts that you have. From tonight, the
development version of gfortran will do (i) but I would be happy to
change that if somebody can demonstrate that an alternative is
correct.
Cheers
Paul
.
- Follow-Ups:
- Re: Select type selector question
- From: Ian Harvey
- Re: Select type selector question
- Prev by Date: Re: equivalence between real and complex arithmetic (previously Re: Why FORTRAN)
- Next by Date: Re: Select type selector question
- Previous by thread: call for papers and EIC
- Next by thread: Re: Select type selector question
- Index(es):