Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
27230 Discussions

Parameterized Derived Types: a question on structure constructors for types with default values of parameters

FortranFan
Honored Contributor II
143 Views

Consider the following simple code involving a parameterized derived type (PDT):

program p

   implicit none

   type :: t(k)
      integer, kind :: k = 0
   end type
   
   !type(t) :: foo = t(k=0)()    ! <-- This works
   
   type(t) :: foo = t()          ! <-- This does not  
   
   print *, "foo%k = ", foo%k

   stop

end program p
Compiling with Intel(R) Visual Fortran Compiler 17.0.0.109 [Intel(R) 64]...
p.f90
p.f90(11): error #6197: An assignment of different structure types is invalid.   [FOO]
ifort: error #10298: problem during post processing of parallel object compilation
compilation aborted for p.f90 (code 1)

It would appear Intel Fortran development team's interpretation of the standard is type parameters must be declared with the type in a structure constructor - is this correct?  It does not seem right, but I could be wrong yet I couldn't find any supporting statement(s) or constraint(s) in the standard document (WD 1539-1 J3/10-007r1 for Fortran 2008, 24 Nov. 2010) in favor of Intel Fortran implementation.  All I find in relation to structure constructors points back to "derived-type-spec" which has the following: see the highlighted line 31 (i.e., point 4.5.9.3)

dtspec.png

 

 

0 Kudos
1 Reply
Steven_L_Intel1
Employee
143 Views

I think this is our error. As I see it, the problem with t() is trying to decide if the () is the type-param-spec-list or the component-spec-list. I think that if () is seen then that is always a component-spec-list, since the type-param-spec-list is not allowed to be empty. I'll send this on to the developers. DPD200415364

Reply