Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
7 Views

Submodules and private derived type components

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
Highlighted
Black Belt
7 Views

It's just a compiler bug.

0 Kudos
Highlighted
7 Views

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

 

Thanks,

Xiaoping Duan

Intel Customer Support

0 Kudos
Highlighted
Beginner
7 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

0 Kudos