Hello there once again,
I have been playing with some upcasting (and downcasting) with Fortran's polymorphism these days, but I am not really sure about what is allowed.
I am basically creating a derived type ExtList_T which extends List_T. The pointers are downcast and then upcast again - or return a nullpointer in case it is not possible to upcast. The part of interest is:
TYPE(ExtList_T), POINTER :: instance1 TYPE(ExtList_T), POINTER :: instance2 CLASS(ExtList_T), POINTER :: ptr_ext CLASS(List_T), POINTER :: ptr_lst (...) ptr_ext => Cast_ExtList(instance1%last()) PRINT *,"Worked? ",ASSOCIATED(ptr_ext) ptr_lst => instance1%last() ptr_ext => Cast_ExtList(ptr_lst) PRINT *,"Worked? ",ASSOCIATED(ptr_ext)
I expected it to print "Worked? T" in both occasions, but only the second one gets printed properly with Intel Fortran. gfortran prints the expected result in both cases.
The sample code follows attached.
Thanks in advance for your attention!