[Bug fortran/33106] Access of components of public entities of private types wrongly allowed

burnus at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Sun Aug 19 18:55:00 GMT 2007



------- Comment #4 from burnus at gcc dot gnu dot org  2007-08-19 18:54 -------
Fortran 2003:
---------------
4.5.1.1   Accessibility
Types that are defined in a module or accessible in that module by use
association have either the PUBLIC or PRIVATE attribute. Types for which an
access-spec is not explicitly specified in that module have the default
accessibility attribute for that module. The default accessibility attribute
for a module is PUBLIC unless it has been changed by a PRIVATE statement
(5.2.1). Only types that have the PUBLIC attribute in that module are available
to be accessed from that module by use association.
The accessibility of a type does not affect, and is not affected by, the
accessibility of its components and bindings.
If a type definition is private, then the type name, and thus the structure
constructor (4.5.9) for the type, are accessible only within the module
containing the definition.
---------------

Fortran 95:
---------------
4.4.1 Derived-type definition
[...]
The accessibility of a derived type may be declared explicitly by an
access-spec in its derived-type-stmt or in an access-stmt (5.2.3). The
accessibility is the default if it is not declared explicitly. If a type
definition is private, then the type name, the structure constructor (4.4.4)
for the type, any entity that is of the type, and any procedure that has a
dummy argument or function result that is of the type are accessible only
within the module containing the definition.
If a type definition contains a PRIVATE statement, the component names for the
type are accessible only within the module containing the definition, even if
the type itself is public (5.1.2.2). The component names and hence the internal
structure of the type are inaccessible in any scoping unit accessing the module
via a USE statement. Similarly, the structure constructor for such a type shall
be employed only within the defining module.
---------------

Fortran 95 prohibits: "If a type definition is private, then [...] any entity
that is of the type, and any procedure that has a dummy argument or function
result that is of the type are accessible only within the module."

But Fortran 2003 only prohibits the type name and structure constructor. Thus
entities and procedures with dummy arguments of this type are allowed.

I would also argue that in Fortran 2003:
 print *, code_green%code
is allowed as "The accessibility of a type does not affect, and is not affected
by, the accessibility of its components". Which agrees with NAG f95.

For
  print *, code_green
I am not fully sure, but one may argue that the type definition of a PRIVATE
type (name) is PRIVATE and thus also the type spec of code_green. This seems to
be the line NAG f95 follows.


-- 


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



More information about the Gcc-bugs mailing list