Dear Paul,

Paul Richard Thomas wrote:
>  c = [ a, b ]
Is exactly the abomination that I did not want to exist!  What happens
if 'a' and 'b' have different dynamic types?

Actually, I start to get lost in the fine prints. One finds:

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

That means that for "[a, b]" one has as constructor type the declared type of each ac-value, which has to be the same. Thus, one has declared type of "a" equals dynamic type of "a" - and the same for "b" with "a" and "b" having the same type.

The question gets more interesting with:
  [ t2 :: a, b]

Here, "a" and "b" need to be of declared type "t2" or of one extension of it - and can have any dynamic type. But due to the "t2" only components which are also in "t2" matter.

See also PR 51864

>  That's accepted by the Cray compiler (7.1.4.111) and produces:
>    5 5 5 5 5 5 5 5

Which is the expected and valid result.

>  Though, if one changes "t ::" to "t2 ::", the result is the slightly
>  surprising
>    5 5 6 6 5 5 5 5
>    6 5 5 5 6 6 6 6

That code is actually invalid. Either both need to be of type "t" or one needs to a type spec and - for "[ t2 :: a, b]" also a different declared type.


>  I think that code is valid Fortran 2003/2008. But to cheer you up: Unlimited
>  polymorphic expressions are not allowed in array constructors (cf. C4107).
Surely it cannot be valid?

"C4106 (R472) An ac-value shall not be unlimited polymorphic."

The reason is probably that class(*) is type compatible with everything thus this loophole had to be closed.

PS I know how to fix PR51634.... will get on to it as soon as I have a moment.

Great!

Tobias

Reply via email to