[J3] [EXTERNAL] Re: Overriding type-bound procedure used in generic
Reuben D. Budiardja
reubendb at ornl.gov
Tue May 6 00:30:10 UTC 2025
Hi Bob,
On 5/5/25 19:29, Robert Corbett via J3 wrote:
>
> In the definition of G_T, you wrote
>
> procedure, private, pass :: &
> Init_T
>
> Did you mean to write
>
> procedure, private, pass :: &
> Init => Init_T
>
> ?
No, I did not. In fact that would be an error since "Init" is already a
generic name in the parent type F_T.
Best,
Reuben
>
> Bob Corbett
>
>> On May 5, 2025, at 9:46 AM, Reuben D. Budiardja via J3 <j3 at mailman.j3-fortran.org> wrote:
>>
>> Hi all,
>>
>> I'd like some help with this.
>>
>> Consider the code below.
>>
>> 1. What should the output be?
>>
>> Two compilers I tried give:
>> Init G
>> Init F
>>
>> while two other compilers give:
>> Init F
>> Init F
>>
>> 2. Should it matter if the access spec of the type-bound statement "Init_T" is changed to "public"? My understanding is that it should not (from 19.5.4 24-007), but in my test if I do that all four compilers then agree in the output:
>> Init_G
>> Init_F
>>
>>
>> Thanks,
>> Reuben
>>
>> -----------------------------------
>>
>> module F_M
>> implicit none
>> private
>>
>> type, public :: F_T
>> contains
>> procedure, private, pass :: &
>> Init_T
>> generic, public :: &
>> Init => Init_T
>> end type F_T
>> contains
>> subroutine Init_T ( FS )
>> class ( F_T ), intent ( inout ) :: &
>> FS
>> print*, 'Init F'
>> end subroutine Init_T
>>
>> end module F_M
>>
>>
>> module G_M
>> use F_M
>> implicit none
>> private
>>
>> type, public, extends ( F_T ) :: G_T
>> contains
>> procedure, private, pass :: &
>> Init_T
>> end type G_T
>> contains
>> subroutine Init_T ( FS )
>> class ( G_T ), intent ( inout ) :: &
>> FS
>> print*, 'Init G'
>> end subroutine Init_T
>>
>> end module G_M
>>
>>
>> program Test
>>
>> use G_M
>> implicit none
>> type ( G_T ), allocatable :: &
>> G
>>
>> allocate ( G )
>> call G % Init ( )
>> call G % F_T % Init ( )
>>
>> end program Test
>>
>>
>
More information about the J3
mailing list