[J3] USE statement – wish: permit specifying additionally the access-spec

Vipul Parekh parekhvs at gmail.com
Sat Nov 16 18:25:31 EST 2019

On Sat, Nov 16, 2019 at 2:10 AM Tobias Burnus via J3
<j3 at mailman.j3-fortran.org> wrote:
> On 11/16/19 12:04 AM, Bill Long via J3 wrote:
> > While I'm not part of the Data subgroup, I’m pretty sure that the design for this feature was not an oversight.  Rather, it likely had to do with the fact that public and private declarations are limited to being only in a module, whereas USE statements (often) appear outside modules.
> Which is not that different from a variable declaration and other places
> where an access-spec can appear – and should already be covered by:
> C817 An access-specshall appear only in the specification-part of a module.
> ..

Yes, I'm not sure I understand Bill's point.  It appears to me Tobias'
proposal does not conflict with current constraint C817 note the
standard states in section 5.1 High level syntax,

1 R504 specification-part is [ use-stmt ] ...
2                              [ import-stmt ] ...
3                              [ implicit-part ]
4                              [ declaration-construct ] ...

Thus R504 suggests <access-spec> can technically appear in USE statements.

But now, should a coder apply the PRIVATE attribute with USE in a
program unit besides a MODULE such as a PROGRAM or FUNCTION/SUBROUTINE
where it would not make sense to have the PRIVATE attribute. processor
will then only have to diagnose it per C817 and this should be no big
deal; it'll be similar to what a processor has to do now e.g., with
PRIVATE attribute in a derived-type declaration:

--- begin code ---
   type :: t
      private  !<-- note this does not make sense in this program unit
   end type
--- end code ---
--- begin code ---
subroutine sub()
   type :: t
      private  !<-- this does not make sense in this program unit
   end type
end subroutine sub
--- end code ---
--- begin code ---
function fun() result(r)
   integer :: r
   type :: t
      private  !<-- this does not make sense in this program unit
   end type
   r = 42
end function fun
--- end code ---

And surely enough, the processor rejects the code in each of the above
3 scenarios:
--- begin processor output ---
Error: PRIVATE statement at (1) is only allowed in the specification
part of a module
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
--- end processor output ---

Thus far, I can only find "thumbs up" to Tobias' suggestion.

Vipul Parekh

More information about the J3 mailing list