Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26734 Discussions

Submodules and private derived type components

may_ka
Beginner
83 Views

Hi there,

the following code compiles and runs although "a" of type "typeA" is decleared "private":

Module Mod_TypeA
  Type :: TypeA
    Private
    Real :: a
  End type TypeA
End Module Mod_TypeA
Module Mod_TypeB
  use Mod_TypeA
  Type :: TypeB
    Type(TypeA) :: TA
  contains
    Private
    Procedure, Pass, Public :: SetA => SubSetA
    Procedure, PAss, Public :: WriteA => SubWriteA
  End type TypeB
  Interface
    Module Subroutine SubSetA(this,a)
      Class(TypeB), Intent(InOut) :: this
      Real, Intent(In) :: a
    End Subroutine
    Module Subroutine SubWriteA(this)
      Class(TypeB), Intent(InOut) :: this
    End Subroutine
  End Interface
End Module Mod_TypeB
Submodule(Mod_TypeB) SubB
contains
  Module Procedure SubSetA
    this%TA%a=a
  End Procedure
  Module Procedure SubWriteA
    write(*,*) this%TA%a
  End Procedure
End Submodule SubB
Program Main
  use Mod_TypeB
  Type(TypeB) :: tb
  call tb%setA(1.0)
  call tb%writeA()
end Program Main

If both the typeB subroutines are put with the typeB module the code won't compile with complaining about a being private.

While I can see the big advantages in submodules for structuring code, what is the advantage of this?? Accessing a of typeA in the main program would require a get/set method anyway, so way skipping it in a submodule?? Is this behaviour part of the standard??

Thanks

 

0 Kudos
3 Replies
IanH
Black Belt
83 Views

It's just a compiler bug.

Xiaoping_D_Intel
Employee
83 Views

I have reproduced the problem and opened a bug report for it. The bug ID is DPD200416441.

 

Thanks,

Xiaoping Duan

Intel Customer Support

may_ka
Beginner
83 Views

Hi,

good to know.

Interestingly the code compiles without error with ifort16, ifort17 and gfortran-6.2 ........... the reason why I was uncertain about whether I missunderstood the standard.

Cheers

Reply