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

Problems with INTERFACE ASSIGNMENT(=)

Jump to solution

I am running into a problem that appears to relate to ambiguous generic procedure references and defined assignment. For a functional example, please see the attached file.

To summarize, we have a generic assignment procedure defined to take two dummy arguments (e.g. lhs and rhs) declared as "class(A)", but it is not being called when code assigns a variable of "type(B)" that extends "type(A)".

With Intel Fortran 2015, the generic assignment IS called and our code works, but with later versions, the generic assignment is NOT called.

The relevant parts of the Intel documentation state that dummy arguments are distinguishable if "hey are both data objects or both known to be functions, and they have different type and kind parameters, or different rank". It also states "When an interface block extends an intrinsic procedure, operator, or assignment, the rules apply as if the intrinsic consists of a collection of specific procedures, one for each allowed set of arguments."

Clearly, later versions of the compiler are deciding to use intrinsic assignment of the extended derived type rather than the user-declared form that takes "class(A)" arguments. This creates significant problems for us because the base class manages reference counting, and with the newer compiler our reference counting is broken.

For those that don't use the older compiler, the output from compiling the attached file with 2015 is

Assigning 1 to 0
Closing 0
Closing 1
Assigning 2 to 1
Closing 1
Closing 2
Assigning 3 to 2
Closing 2
Closing 3
Assigning 4 to 3
Closing 3
Closing 4
Assigning 5 to 4
Closing 4
Closing 5
Closing 42
Closing 5

With the newer compilers, the "Assigning..." lines are missing. Without them, our reference counts are not incremented (in the full code) and the finalization causes reference counts prematurely go to zero and release resources too soon.

Thoughts?

0 Kudos

Accepted Solutions
Highlighted
New Contributor II
37 Views

Dear Thomas F.,

my first thought is that the generic interface (as opposed to the specific subroutine) is declared private in the module in your attached program and therefore not accessible from the program, it is possible older compilers did not strictly enforce this.

Suggestion: state "public :: assignment(=)" in the module declaration part.

(https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-public)

Kind regards
Ferdinand

 

 

View solution in original post

0 Kudos
2 Replies
Highlighted
New Contributor II
38 Views

Dear Thomas F.,

my first thought is that the generic interface (as opposed to the specific subroutine) is declared private in the module in your attached program and therefore not accessible from the program, it is possible older compilers did not strictly enforce this.

Suggestion: state "public :: assignment(=)" in the module declaration part.

(https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-public)

Kind regards
Ferdinand

 

 

View solution in original post

0 Kudos
Highlighted
Beginner
37 Views

Yes! This fixed the issue. Apparently in 2015 generic interfaces were (incorrectly) public by default.

Thank you!

Ferdinand T. wrote:

Dear Thomas F.,

my first thought is that the generic interface (as opposed to the specific subroutine) is declared private in the module in your attached program and therefore not accessible from the program, it is possible older compilers did not strictly enforce this.

Suggestion: state "public :: assignment(=)" in the module declaration part.

(https://software.intel.com/en-us/fortran-compiler-developer-guide-and-re...)

Kind regards
Ferdinand

 

 

0 Kudos