Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29413 Discussions

Function returning pointer to class data

lopes8070
Beginner
2,212 Views
You'll have to excuse me if I do not format correctly, this is my first post. I am recieving an error when trying to use a function that returns a pointer to some class data and am unclear why this would happen (ifort (IFORT) 11.1 20091012). Let me draw up some modules.

[plain]module typeAmodule
implicit none
private
public :: A, GetPtrB
type A
private
type(B), pointer:: ptrB
end type
contains
function GetPtrB(typA) return(res)
type(A)::typA
type(B), pointer::res
res => typeA%ptrB
end function GetPtrB
end module typeAmodule

module typeCclass
use typeAmodule
implicit none
private
public :: C
type, extends(anotherClass)::C
type(A), pointer::ptrA
contains
procedure, public, pass :: GetB
end typeC
contains
function GetB(typC) result(res)
class(C), intent(in)::typC
type(B), pointer::res
res => GetPtrB(typC%ptrA)
end function GetB
end module typeCclass

program SomeProgram
include typeCclass
implicit none
type(C)::typC
type(B), pointer::ptrB
...
...
ptrB => typC%GetB() !<<----
end program SomeProgram[/plain]


The compiling error I get is "error #6678: When the target is an expression it must deliver a pointer result." at the line marked with the '!<<----'. What I don't understand is the function 'GetB' is returning a pointer result, 'type(B), pointer', and is almost exactly like the function 'GetPtrB' except it is defined in the class, not as a subroutine accessing data in a type. I have done some research online, and as far as I can tell, I am using the function correctly. Any help is greatly appreciated, and please ask any questions if you need more clarification.
0 Kudos
14 Replies
Steven_L_Intel1
Employee
2,212 Views

Please post a compilable example. Your paraphrase here has too many errors and missing declarations. ("return" instead of "result", "include" instead of "use", no declaration for B, etc.) It is impossible to tell what the real problem is.
0 Kudos
lopes8070
Beginner
2,212 Views

Please post a compilable example. Your paraphrase here has too many errors and missing declarations. ("return" instead of "result", "include" instead of "use", no declaration for B, etc.) It is impossible to tell what the real problem is.

Sorry for the bad, quick programming. Here is a (non)compilable program that reproduces the result. As you can see the function GetCA returns a pointer, but the compiler throws an error saying it doesn't. I'm sure I'm not programming correctly, but after researching this problem on the internet for a few days, I am at my wits end as to what error I am doing. I'm grateful for any help you can provide.
0 Kudos
Steven_L_Intel1
Employee
2,212 Views
Ok. I agree that the error seems suspect. I'll run this by the developers.
0 Kudos
lopes8070
Beginner
2,212 Views
Ok. I agree that the error seems suspect. I'll run this by the developers.

I'm sorry for my ignorance, but what happens now? Do I wait for a replay to this thread, or just wait for it to be address on next release?
0 Kudos
Steven_L_Intel1
Employee
2,212 Views

I will update this thread as I learn more. Perhaps I'll find a workaround. If it is really a bug, it will be fixed in a future update and I'll say so.
0 Kudos
lopes8070
Beginner
2,212 Views

I will update this thread as I learn more. Perhaps I'll find a workaround. If it is really a bug, it will be fixed in a future update and I'll say so.

For anyone else who runs into this problem, a workaround, albiet a bad one, is to declare the variable in ClassC public and call the access routines in TypeB directly.

use TypeBModule
ptrA => GetAB(classC%ptrB)
instead of
ptrA => classC%GetCA()

However, this is not the way it should be done because it changes variable in the C class to public, ruining the encapsulation.
0 Kudos
Steven_L_Intel1
Employee
2,212 Views
Our issue ID is DPD200148269.
0 Kudos
lopes8070
Beginner
2,212 Views
Our issue ID is DPD200148269.

Hey Steve,
Thanks for your timely response on this. At least now I know I'm not going crazy. is there anything I should do with that issue ID to track this bug or continue to sit and wait. I am also running into similar problems with procedure calls inside of a class (though I can't reproduce this bug at this time, i.e. haven't tried yet).
0 Kudos
Steven_L_Intel1
Employee
2,212 Views
There's nothing else you need do - I'll track the issue and update this thread when there is news. If you find other issues, please let us know.

Update 4 is coming out in the next week or so - the issue you reported here isn't fixed in that.
0 Kudos
lopes8070
Beginner
2,212 Views
There's nothing else you need do - I'll track the issue and update this thread when there is news. If you find other issues, please let us know.

Update 4 is coming out in the next week or so - the issue you reported here isn't fixed in that.

I am trying to reproduce the 2 or 3 other bugs but, as you can image, it's difficult. It throws an error in my code, but when I try to reproduce it in the demo code, it works fine. sigh... I'll try to get it to work.
0 Kudos
lopes8070
Beginner
2,212 Views
Quoting - lopes8070

I am trying to reproduce the 2 or 3 other bugs but, as you can image, it's difficult. It throws an error in my code, but when I try to reproduce it in the demo code, it works fine. sigh... I'll try to get it to work.

I am also running into this message a lot:

: catastrophic error: **Internal compiler error: segmentation violation signal raised** Please report this error along with the circumstances in which it occurred in a Software Problem Report. Note: File and line given may not be explicit cause of this error.

as well as,

: error #6618: The INTERFACE/CONTAINS stack is full. This means that modules are being 'used' in a circular way.

But I do not have any circular 'use' statements. I can honestly say, I have no clue what either of these mean. The first time I go the second error, I was able to avoid it by not using interfaces to class procedures, but now I am getting it no matter what (with no interfaces to class procedures). I have no work around as of yet, for the catastrophic error.
0 Kudos
Steven_L_Intel1
Employee
2,212 Views

The first is almost always a compiler bug. Please provide us a test case and tell us what switches you used.

The second might also be a compiler bug, but hard to say. Please provide us a test case.
0 Kudos
Steven_L_Intel1
Employee
2,212 Views
The 6678 error is fixed, and the fix should appear in Update 6. The 6618 issue is being investigated as issue DPD200152345.
0 Kudos
Steven_L_Intel1
Employee
2,212 Views
The 6678 issue is fixed in Update 6, available now. The 6618 issue is not yet fixed.
0 Kudos
Reply