problem with a function initializing a derived type

Hello,
I have a weird problem with a function returning an instance of a derived type. To make things more simple than my real problem, let say I have a derived type:

type :: A
real :: x
end type A

I have a function :

function genA( x0 ) result( instA)
type(A) :: instA
real :: x0
instA%x = x0
end function genA


and finally a program where I have

type(A) :: mA
mA = genA(4.5)
print *, mA%x

and instead of 4.5 I get 0 or anything mA%x was initialized with before calling genA.

My problem is that I have in my program several derived types that I “construct” like this with no problem, and one where the “constructor” function ( like genA ) does not change anything to the initial value of the data members like for the case just above ( which is not a real case ).
Another point is that the compilation with pgfortran is ok ( but I have this problem when running the program )
Last point : with other compilers ( gfortran and ifort ) , I do not have this problem at all.

I could not write simpler examples than the real one in my program that shows the same behaviour so someone could try to reproduce it. It only happens with one particular derived type in my program.

If my explanation is clear enough and someone has an idea of where I should look at I will be happy !
Thanks in advance.
Marc

Hi Marc,

Given that the error doesn’t not occur everywhere or in the simple case, and that it works with other compilers, then most likely our compiler is at fault. Can you please send a report to PGI Customer Support (trs@pgroup.com) with the complete code? or at least enough to reproduce the error?

Thanks,
Mat

Hi Mat,
it is difficult for me to send the code, as the module I have problems with use almost all my other modules. By some standards it is not a big code ( appr. 5000 lines, comments in french … ) but it would be more comfortable, also for the PGI customer support maybe, if I was able to reproduce my problem in a smaller program.
Anyway I found a simple workaround: instead of using a function I use a subroutine to initialize the instance of derived type. To compare with the simple code I gave in the first post of this thread, what I do now is:

subroutine genA( instA, x0 )
type(A) :: instA
real :: x0
instA%x = x0
end subroutine genA


and finally a program where I have

type(A) :: mA
call genA(mA,4.5)
print *, mA%x

and now it works as intended.

Best regards.
Marc