(j3.2006) Parent component of extension of abstract type

Van Snyder Van.Snyder
Thu Nov 12 19:45:18 EST 2015


NAG build 1052 and ifort version 15.0.2 both refuse to compile it.

140: ifort Test_Abstract_Component.f90
Test_Abstract_Component.f90(17): error #8314: If the rightmost part-name
is of abstract type, data-ref shall be polymorphic.   [T0]
  print '(a,i0)', 'V1 ', v1, ' V1%T0 ', v1%t0
-------------------------------------------^
compilation aborted for Test_Abstract_Component.f90 (code 1)
[NAG Fortran Compiler normal termination]
144: NAG_1052 Test_Abstract_Component.f90
NAG Fortran Compiler Release 6.0(Hibiya) Build 1052
Questionable: Test_Abstract_Component.f90, line 18: Variable V2 set but never referenced
Error: Test_Abstract_Component.f90, line 12: V1%T0 is of abstract TYPE(T0)
Error: Test_Abstract_Component.f90, line 15: V2%T0 is of abstract TYPE(T0)
[NAG Fortran Compiler error termination, 2 errors, 1 warning]

The prohibition is C611 in 15-007r2.

C611 (R611) If the rightmost <part-name> is of abstact type,
     <data-ref> shall be polymorphic.

If this were moved to be a restriction on R1223 it would prevent
invoking type-bound procedures, but not referencing components.

C1233a (R1223) If the rightmost <part-name> of <data-ref> is of abstract
       type, <data-ref> shall be polymorphic.

On Thu, 2015-11-12 at 16:32 -0800, Damian Rouson wrote:
> 
> > On Nov 12, 2015, at 1:32 PM, Van Snyder <Van.Snyder at jpl.nasa.gov> wrote:
> > 
> > It seems a bit strange that I can't access the parent component of an
> > object of a type that is an extension of an abstract type, but I can
> > access components of the parent component.  Is this what we intended?
> > 
> > program P
> > 
> >  type, abstract :: T0
> >    integer :: N = 42
> >  end type T0
> > 
> >  type, extends(t0) :: T1
> >  end type T1
> > 
> >  type(t1) :: V1, V2
> > 
> >  print '(a,i0)', 'V1 ', v1
> >  print '(a,i0)', 'V1%T0 ', v1%t0      ! Prohibited
> >  print '(a,i0)', 'V1%T0%n ', v1%t0%n
> > 
> >  v2 = v1
> >  v2%t0 = v1%t0                        ! Prohibited
> >  v2%t0%n = v1%t0%n
> 
> Where is or are the relevant prohibition(s)?  The Cray, Portland
> Group, and GNU Fortran compilers all accept the above code and the
> resulting executable terminates without error:
> 
> $ gfortran van.f90 
> $ ./a.out
> V1 42
> V1%T0 42
> V1%T0%n 42
> 
> Are the aforementioned compilers accepting non-conforming code?  I
> haven?t tried other compilers.
> 
> On a peripherally related note, I?m surprised that I didn?t know you
> could print an object of derived type without derived type I/O, but I
> guess that?s because the one rule of OOP that I adhere to most
> strongly is data privacy.   The first print statement in the above
> code wouldn?t work if the types were encapsulated in a module and
> given the private attribute.  This makes me really wish we the
> list-directed version of the first print statement were allowed with
> private components:
> 
> print *, 'V1 ?,v1
> 
> If the list-directed version worked when type T1 is defined in a
> module and has private components, it would eliminate a lot of my need
> for derived type I/O.  I hope that allowing this can be considered in
> a future standard.  The list-directed print statement exploits no
> information about the components.  Of course, the statement?s behavior
> could change if the type?s definition changes, but that?s also true
> for derived type I/O so it feels like an artificial restriction.
> 
> 
> D
> 
> 
> 
> _______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3





More information about the J3 mailing list