- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The code below implements an class hierachy with an abstract parent and two progeny and a generic assignment operator defined at the parent level. The operator points to a deferred routine which is subsequently defined for the two progeny classes.
Module Mod_AA Type, abstract :: ta contains Generic, Public :: Assignment(=) => CP Procedure(SubCP), Deferred, PAss :: CP End type ta Abstract Interface Subroutine SubCP(this,other) Import ta Class(ta), Intent(InOUt) :: this Class(ta), Intent(In) :: other end Subroutine SubCP End Interface Type, extends(ta) :: tb integer :: ib contains Procedure, Pass :: CP => SubCPB End type tb Type, extends(ta) :: tc integer :: ic contains Procedure, Pass :: CP => SubCPC End type tc contains Subroutine SubCpB(this,other) class(tb), Intent(inout) :: this Class(ta), intent(in) :: other Select Type(x=>other) Class Is(tb) this%ib=x%ib Class Is(tc) this%ib=x%ic End Select End Subroutine SubCpB Subroutine SubCpC(this,other) class(tC), Intent(inout) :: this Class(ta), intent(in) :: other Select Type(x=>other) Class Is(tc) this%ic=x%ic Class Is(tb) this%ic=x%ib End Select End Subroutine SubCpC End Module Mod_AA Program Test use Mod_AA Type(tb) :: b type(tc) :: c c%ic=1 b=c write(*,*) b%ib End Program Test
From my understanding the code is correct and should work, and when using gfortran, it compiles and runs. However, using ifort 17.07 and 18.02 yields a compile time error:
user@linux:~$ ifort tmp.f90 tmp.f90(51): error #6197: An assignment of different structure types is invalid.b=c ----^ compilation aborted for tmp.f90 (code 1)
Is this a compiler bug or does gfortran allow for code which does not comply with the standard???
Any comments appreciated.
Chees
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That would have been a compiler bug. It compiles ok with current beta.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page