(j3.2006) Did we intend this to be OK?

Van Snyder Van.Snyder
Wed Oct 7 21:14:37 EDT 2015


On Thu, 2015-10-08 at 09:23 +0900, Cohen Malcolm wrote:
> Van Snyder asks:
> >Did we intend this to be OK?
> 
> There's no program here, so hard to be sure...
> 
> He asserts:
> >Other than within the module where T1 is defined, one cannot reference
> >either x%p or x%g.
> 
> Yes.
> 
> >  One can (apparently) access x%p using y%g, even in a
> >different module.
> 
> No.
> 
> I do not see how these differ from other similar public/private visibility 
> cases, e.g.

I think these differ from Malcolm's illustration (further below), at
least if the type definitions are in the same module:

module M
  type T1
  contains
    procedure, private, nopass :: P
    generic, private :: G => P
  end type T1

  type, extends(t1) :: T2
  contains
    procedure, nopass :: Q
    generic :: G => Q
  end type T2

contains

  subroutine P ( A )
    integer :: A
    print *, 'Got to P'
  end subroutine P

  subroutine Q ( X )
    real :: X
    print *, 'Got to Q'
  end subroutine Q

end module M

program MAIN

  use M

  type(t1) :: X
  type(t2) :: Y
  call y%g(1)
  call y%g(1.0)

end program MAIN

ifort 15.0.2 compiles it without objection and prints

Got to P
Got to Q

nagfor build 1052 objects:

Error: Generic_Test.f90, line 11: GENERIC statement implicitly specifies
the PUBLIC attribute for generic type-bound procedure G of type T2, but
the inherited accessibility is PRIVATE

C471 applies only within a single derived type definition.

I could not find a constraint or other normative text to support this
error message.  Maybe it exists but either doesn't contain the word
"access", or it's not in Clause 4.

If we intended to prohibit this, C471 should have included "or any of
its extensions".

Perhaps we intended for Y%G to be public even though X%G is private.  In
that case, it might be reasonable to specify that X%P and Y%P are not
accessible via Y%G in scoping units where X%G and X%P are not
accessible.  If X%P were public, X%G private, and Y%G public, would it
be reasonable to access P via Y%G?  It's conceivably possible to explain
this, but perhaps a bit messier than we want to touch.

> 
> Module junk2
>   Private g
>   Interface g
>     Module Procedure p1
>   End Interface
> Contains
>   Subroutine p1
>     Print *,'p1'
>   End Subroutine
> End Module
> Module junk3
>   Use junk2
>   Interface g
>     Module Procedure p2
>   End Interface
> Contains
>   Subroutine p2
>     Print *,'p2'
>   End Subroutine
> End Module
> Program test
>   Use junk3
>   Call g
> End Program
> 
> There is no doubt that the PRIVATE G in junk2 does not "connect up" with the 
> PUBLIC G in junk3, and that this is therefore
> (a) unambiguous
> (b) prints "p".
> 
> I am aware that several compilers do not get the visibility of type-bound 
> generics quite right here, so possibly Van is being misled by a compiler 
> bug.
> 
> Cheers,





More information about the J3 mailing list