The code below will fail because of
> type(t),allocatable :: foo
> foo = t()
foo is not allocated at the point where the operator(=) procedure is called. So you get a segfault.
If this is changed to
> type(t) :: foo
> foo = t()
then there are no errors with the compilers I tried.
> On Mar 22, 2018, at 4:55 PM, Vipul Parekh <[log in to unmask]> wrote:
>
> On Thu, Mar 22, 2018 at 4:09 PM, Bill Long <[log in to unmask]> wrote:
>> I believe that the type-bound-procedure wins. ..
>
> Bill,
>
> Do you think the standard states anywhere "the type-bound procedure
> wins”?
The supporting normative text is in the scoping rules for local identifiers:
• Identifiers of entities, other than statement or construct entities (19.4), in the classes
…
• (2) type parameters, components, and type-bound procedure bindings, in a separate class for each type,
…
• are local identifiers.
In the generic interface rules section there is a explanatory note:
"In most scoping units, the possible sources of procedures with a particular generic identifier are the accessible generic identifiers specified by generic interface blocks or GENERIC statements and the generic bindings other than names for the accessible objects in that scoping unit. In a type definition, they are the generic bindings, including those from a parent type.”
Note particularly the last sentence.
Cheers,
Bill
> In your modified example with the 3 compilers you tried, what
> "fun" will happen with any instruction involving the passed object?!
> As in say the modification below, note the lines marked A and B:
>
> module m
> type :: t
> integer :: i = 0 !<--- A
> contains
> procedure :: assign_class_t
> generic :: assignment(=) => assign_class_t
> end type
> contains
> subroutine assign_class_t( this, rhs )
> class(t), intent(inout) :: this
> type(t), intent(in) :: rhs
> print *, "called assign_class_t"
> this%i = rhs%i !<--- B
> end subroutine
> end module m
>
> program test
> use m
> type(t),allocatable :: foo
> foo = t()
> end program test
>
> Thanks,
> Vipul Parekh
Bill Long [log in to unmask]
Principal Engineer, Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9143
Cray Inc./ 2131 Lindau Lane/ Suite 1000/ Bloomington, MN 55425
|