Array constructor with type-spec

Array constructor with type-spec


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?

8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The syntax you want is:

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

though in this case the type-spec is not required. In general, the Intel compiler does support a type-spec in array constructors but for some reason doesn't here. I'll ask the developers why. You would more likely want to use a type-spec in something like:




Intel Fortran, as an extension, allows the latter without the type-spec.

I'm not entirely sure what use a derived type here is since the standard requires that all ac-values be of that type.

Retired 12/31/2016

> The syntax you want is:

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

Are you 100% sure? Other compilers work fine, plus type() appears everytime a user-derived type is used in the same context as an intrinsic type.

>I'm not entirely sure what use a derived type here is since the standard requires that all ac-values be of that >type.

It is not the most crucial thing, definitely. But on one hand, for the sake of clarity, but most importantly, if implicit type conversion is used.



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."

Retired 12/31/2016

Thanks for clearing that :) I guess that my first contribution was just being a bit of a quibbler...

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.

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,


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.   [A]c = [a :: a(s='PAS'),a(s='SED')] ! This fails

Retired 12/31/2016

Leave a Comment

Please sign in to add a comment. Not a member? Join today