(j3.2006) More on default initialization and structure constructors

Cohen Malcolm malcolm
Tue Nov 22 03:39:58 EST 2016


>Suppose I have two types:
>
>  type :: T1
>    integer :: i1 = 0
>  end type T1
>
>  type, extends(t1) :: T2
>    integer :: I2 = 0
>  end type T2
>
>Is t2(i2=42) a valid structure constructor,

Yes.

> or do I need t2(t1(),i2=42)?

No.

Type extension is intended to work as if you had a type with all the 
inherited things actually there in the type.  The parent pseudo-component is 
just a convenience feature, and is not supposed to make things happen by 
itself.  (Well, other than the memory layout.)

>C492 (12-007)

Why are you using 12-007?  Surely you should be using the current draft!

> says "A component-spec shall be provided for a
>nonallocatable component unless it has default initialization...."

This is obviously talking about normal components, not the parent 
pseudo-component, as it goes on:
"or is inheritance associated with a subcomponent of another component for 
which a component-spec is provided".

(This is easy to fix, just stick "nonancestor" in there; a bit ugly but it 
works.)

In any case the wording is wrong, it should be requiring the component to be 
default-initialized, not just "have" default initialization, as that is true 
if any potential subobject component is default-initialized.

(Again, probably a simple fix.)

>If the parent type has default initialization for every component, does
>the parent component have default initialization?

No, the parent component has default initialization if ANY component of the 
parent type has default initialization.  So the wording of this constraint 
would appear to be wrong as noted above.

>Suppose I have a third type
>
>  type :: T3
>    integer :: I3 = 0
>    type(t2) :: V3
>  end type T3
>
>Is t3(i3=42) a valid structure constructor,

No.

> or do I need t3(i3=0,v3=t2())?

Yes.

>If every component of a type has default initialization, does a
>component of that type (e.g. V3 in type T3 above) have default
>initialization,

V3 is not default-initialized, which is the term which the constraint should 
have used (as explained above, "has default init" is very different).

> or does it need to be explicitly given a component-spec?

Yes.

Cheers,
-- 
.............Malcolm Cohen, NAG Oxford/Tokyo. 




More information about the J3 mailing list