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

Array constructor with type-spec

Sergio
Beginner
1,041 Views
Hi,

According to The Fortran 2003 handbook (Adams, Brainerd, Hendricksson), p. 112, it should be possible to declare the type of an array as
[ type-spec :: ac-value-list ]
Apparently type specification is not supported by ifort. For instance, this code fails to compile:
>>>>>>>>>>>>>>>>>>>>>>>>>>
program test
implicit none
type a
integer :: b
end type

type(a) :: c(2)

c=[type(a) :: a(b=2),a(b=3)]

end program
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Am I doing something wrong? Are there plans to implement this feature?
0 Kudos
7 Replies
Steven_L_Intel1
Employee
1,041 Views
Sorry, you are right. It should be TYPE(a). Escalated as DPD200166644.

There is no implicit type conversion in the language and the standard is quite explicit saying "C4105 (R 469) If type-spec specifies a derived type, all ac-value expressions in the array-constructor shall be of that derived type and shall have the same kind type parameters as specified by type-spec."
0 Kudos
Sergio
Beginner
1,041 Views
Thanks for clearing that :) I guess that my first contribution was just being a bit of a quibbler...
0 Kudos
IanH
Honored Contributor III
1,041 Views
The syntax you presented for the array-constructor in reply #1 (just "type-name ::", not "TYPE(type-name) ::") seems more consistent with the rules in the standard for an array-constructor.
0 Kudos
Sergio
Beginner
1,041 Views

This is old news, but I now can confirm that the syntax that Steve mentioned ( [a ::], not [type(a) ::] ) is the correct one. So you can scrap DPD200166644.

Best regards,

Sergio

0 Kudos
Steven_L_Intel1
Employee
1,041 Views

My earlier reply was wrong. As you say, the legal syntax is a:: not type(a)::. Nevertheless, ifort doesn't like the valid syntax either, in my tests.

program U81063

type a
  character(3) :: s
end type a

type(a), dimension(2) :: c

c = [a(s='FAI'),a(s='LED')]  ! This is accepted
c = [a :: a(s='PAS'),a(s='SED')] ! This fails

print '(2A3)',c%s

end program u81063


U81063.f90(10): error #5082: Syntax error, found '::' when expecting one of: , (/ : ]
c = [a :: a(s='PAS'),a(s='SED')] ! This fails
-------^
U81063.f90(10): error #6478: A type-name must not be used as a variable.   c = [a :: a(s='PAS'),a(s='SED')] ! This fails

0 Kudos
Reply