[Patch, Fortran] SELECT TYPE with associate-name
Tobias Burnus
burnus@net-b.de
Mon Oct 5 14:04:00 GMT 2009
On 10/05/2009 03:52 PM, Tobias Burnus wrote:
> On 10/05/2009 02:06 PM, Janus Weil wrote:
>
>> here is a patch that implements a small enhancement for the SELECT
>> TYPE construct, namely using an associate-name, as in:
>> SELECT TYPE ( x => ... )
>>
>>
>
I think you need to encapsulate your new variable declaration in a BLOCK
to get a local variable. Otherwise you reject valid code. The following
program compiles with NAG f95 and ifort and prints "5". With gfortran +
your patch one gets a compile time error.
* * *
"16.3 Statement and construct entities": "...A variable that appears as
an index-name in a FORALL construct or an associate-name in a SELECT
TYPE or ASSOCIATE construct is a construct entity." [...]
"Except for a common block name or a scalar variable name, a global
identifier or a local identifier of class (1) (16.2) in the scoping unit
that contains a statement shall not be the name of a statement entity of
that statement. Within the scope of a statement entity, another
statement entity shall not have the
same name. If a global or local identifier accessible in the scoping
unit of a statement is the same as the name of a statement entity in
that statement, the name is interpreted within the scope of the
statement entity as that of the statement entity. Elsewhere in the
scoping unit, including parts of the statement outside the scope of the
statement entity, the name is interpreted as the global or local
identifier."
(You might additionally need to add some more checks regarding the name,
I have not checked.)
Tobias
type :: t1
integer :: i = -1
class(t1), pointer :: c
end type t1
type, extends(t1) :: t2
integer :: j = -1
end type t2
type(t2), target :: b
integer :: aa
b%c => b
aa = 5 ! valid
select type (aa => b%c)
type is (t1)
aa%i = 1
! aa = 5 ! invalid, is correctly rejected
type is (t2)
aa%j = 2
end select
print *, aa ! valid, shall print 5
end
More information about the Fortran
mailing list