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

Change in behavior of derived-type component initialization expressions

David_V_3
Beginner
408 Views

The following program compiles and runs with Intel Visual Fortran versions 10.1 through 14.0:

PROGRAM TESTTYPE

   TYPE MYTYPE
      INTEGER :: I => 0
   END TYPE MYTYPE
   
   TYPE(MYTYPE) :: X
   
   WRITE(*,*) X%I
         
END PROGRAM TESTTYPE

However, in versions 15 & 16 it fails with the following message:

testtype.f90(4): error #6680: A constant is not permitted in this context.   [0]

      INTEGER :: I => 0
----------------------^
compilation aborted for testtype.f90 (code 1)

It is noted that replacing the '=>' operator with '=' in the initialization expression works in all versions of the compiler tested.

------------------------------------------------------------------------------------------------------

QUESTION: What is the reason for the change in behaviour?

------------------------------------------------------------------------------------------------------

The IVF documentation states:

Is an initialization expression, or for pointer components, => NULL( ).

If init-ex is specified, a double colon must appear in the component definition. The equals assignment symbol (=) can only be specified for nonpointer components.

The initialization expression is evaluated in the scoping unit of the type definition.

One reading of the highlighted clause is that '=' or '=>' could be used for non-pointer components but that '=' must not be used for pointer components.

Many thanks,

David.

 

 

 

 

 

0 Kudos
7 Replies
Kevin_D_Intel
Employee
408 Views

I will research this changed behavior David and let you know what I find.

0 Kudos
andrew_4619
Honored Contributor II
408 Views

Surely the compiler is just identifying bugs in your code that it did not identify before. The new behavior is an improvement!

0 Kudos
IanH
Honored Contributor II
408 Views

For what it is worth, the text in the current standard makes it absolutely clear.

"If => appears in component-initialization, POINTER shall appear in the component-attr-spec list. If = appears in component-initialization, neither POINTER nor ALLOCATABLE shall appear in the component-attr-spec-list."

 

0 Kudos
Kevin_D_Intel
Employee
408 Views

Development believes parsing was also cleaned up for incorrect uses (as others noted regarding the Fortran Standard) of “=>” for non-pointer initialization in conjunction with this earlier post and internal tracking id DPD200157846 which was fixed in the 15.0 release, so this is the reason for the change in behavior.

I notified our Documentation writers about clarifying the init-ex component description and the statement you cited to make the "=" and "=>" uses clearer in a future revision.

(Internal tracking id: DPD200376067)

0 Kudos
David_V_3
Beginner
408 Views

Thank you for looking into this issue Kevin and thank you Ian H for pointing out relevant text in the standard ... the latter may be of assistance to the Intel documentation writers in their review of the init-ex component description.

Regards,
David.

0 Kudos
Kevin_D_Intel
Employee
408 Views

You're welcome David. Yes, I agree. I passed along IanH's earlier citation to the Doc writers. It was helpful and very clear.

0 Kudos
FortranFan
Honored Contributor II
408 Views

Kevin Davis (Intel) wrote:

You're welcome David. Yes, I agree. I passed along IanH's earlier citation to the Doc writers. It was helpful and very clear.

Kevin,

Please see my Message #11 in another thread where documentation is being discussed:

https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/592538#comment-1839556

0 Kudos
Reply