BUG using polymorphic variables with non_overriden attribute
vsande
vsande@cimne.upc.edu
Wed Feb 17 08:05:00 GMT 2016
Hi all,
something new about this?
Thank you,
VÃctor
El 19/01/16 a las 10:10, vsande escribió:
> Hi again,
>
> Sorry. I have had some some problems with code format and copy/paste.
> The code below is no well formated (I think)
>
> module A
> implicit none
> type :: A_t
> contains
> procedure :: foo => A_foo
> end type
> contains
> subroutine A_foo(this)
> class(A_t), intent(in) :: this
> print*, "I'm A"
> end subroutine
> end module
>
> module B
> use A
> implicit none
> type, extends(A_t) :: B_t
> contains
> procedure, non_overridable :: foo => B_foo
> end type
> contains
> subroutine B_foo(this)
> class(B_t), intent(in) :: this
> print*, "I'm B"
> end subroutine
> end module
>
> program test_non_overridable
> use A
> use B
> implicit none
> class(A_t), pointer :: my_object
> allocate(B_t :: my_object)
> call my_object%foo()
> ! A_t class pointer my_object
> ! allocated as B_t must call B_foo when
> ! calling my_object%foo()
> ! With gfortran 5.3 return "I'm A"
> end program
>
> Best,
> VÃctor.
>
> El 19/01/16 a las 10:05, vsande escribió:
>>
>> Hi all,
>>
>> is the first time that I report a BUG and I'm not sure of doing the
>> things well.
>>
>> Sorry in advance.
>>
>> I think that is the same BUG reported in
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61284 , but in this case
>> the procedure of the parent class is not deffered.
>>
>> In the code snippet below, you can see a polymorfic instance of class
>> (|A_t|) allocated as the child class (|B_t|).
>>
>> |A_t| implements a procedure |foo()| and |B_t| overloads this
>> implementation with the |NON_OVERRIDABLE| attribute.
>>
>> When calling to the |foo()| procedure from the allocated as |B_t|
>> instance, it must call the child procedure instead the parent procedure.
>>
>> With gfortran 5.3 parent procedure is called.
>>
>> |module A implicit none type :: A_t contains procedure :: foo =>
>> A_foo end typecontains subroutine A_foo(this) class(A_t), intent(in)
>> :: this print*, "I'm A" end subroutine end module module B use A
>> implicit none type, extends(A_t) :: B_t contains procedure,
>> non_overridable :: foo => B_foo end typecontains subroutine
>> B_foo(this) class(B_t), intent(in) :: this print*, "I'm B" end
>> subroutine end module program test_non_overridable use A use B
>> implicit none class(A_t), pointer :: my_object allocate(B_t ::
>> my_object) call my_object%foo() ! A_t class pointer my_object!
>> allocated as B_t must call B_foo when ! calling my_object%foo() !
>> With gfortran 5.3 return "I'm A" end program|
>>
>> Best regards,
>> VÃctor.
>>
>>
>
More information about the Fortran
mailing list