This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/51864] [OOP] ALLOCATE with polymorphic array constructor as SOURCE=


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51864

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-01-15 23:25:55 UTC ---
(In reply to comment #0)
> class(t), allocatable :: a(:), b(:), c(:)
> allocate(t2 :: a(3))
> allocate(t2 :: b(5))
> allocate(c(8), source=[ a, b ])

Actually, this part of the program is invalid as Fortran 2008 demands (4.8
Construction of array values):

"The dynamic type of an array constructor is the same as its declared type."

Thus, one can use
 [ a, b ]
but only if both are of the declared and dynamic type "t", cf.

"If type-spec is omitted, each ac-value expression in the array constructor
shall have the same length type parameters; in this case, the declared type and
type parameters of the array constructor are those of the ac-value
expressions."

However, one is still allowed to use:

 [ t2 :: a, b]

in that case, "a" and "b" need to have a declared type "t2" or an extension of
"t2" as declared type - and can have any dynamic type.

"If type-spec appears, it specifies the declared type and type parameters of
the array constructor. Each ac-value expression in the array-constructor shall
be compatible with intrinsic assignment to a variable of this type and type
parameters. Each value is converted to the type parameters of the
array-constructor in accordance with the rules of intrinsic assignment
(7.2.1.3)."

And in 4.3.1.3 CLASS, one finds "type compatible" defined as:

"A polymorphic entity that is not an unlimited polymorphic entity is type
compatible with entities of the same declared type or any of its extensions.
Even though an unlimited polymorphic entity is not considered to have a
declared type, it is type compatible with all entities. An entity is type
compatible with a type if it is type compatible with entities of that type."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]