(j3.2006) Question about specification expressions

Van Snyder Van.Snyder
Wed Mar 9 20:32:04 EST 2016

In this little program

program P

  integer, allocatable :: A(:)
  integer :: N

  read ( *, * ) n
  allocate ( a(max(n,1)) )

  a(1) = size(a,1)

    integer :: B(size(a,1)), C(a(1))
  end block

end program P

Is the declaration of B acceptable?

7.1.11p2(9)(b)(ii) says that if a specification inquiry appears in a
specification expression, a variable that is an argument cannot be an
optional dummy argument (which A is not), and the property inquired
cannot be deferred.

The bound of A is deferred.  Is the size still deferred after A is
allocated?  If so, the declaration of B is invalid.

There is nothing in 7.1.11 about allocatable variables (or pointers), so
the declaration of C is apparently acceptable.

It seems a bit bizarre to prohibit using an inquiry of the size of an
allocatable array in a specification expression, but not saying anything
about using the value of an element of that array in a specification

Change the ALLOCATABLE attribute of A to POINTER and the same questions

Change the inquiry to one about a deferred length parameter and the same
questions arise.

Make the variable a module variable and try to use it in a specification
expression in a module procedure and the same questions arise (i.e., the
BLOCK is a red herring).

It seems that 7.1.11p2(9)(b)(ii) was a bit overzealous.  It's not
permitted to reference an undefined variable in any expression.  If a
reference to an unallocated variable appears in a specification
expression, that's taboo, but couldn't be prevented in 7.1.11p2 because
that's effectively part of a constraint.  Prohibiting reference to a
deferred property, that might not be deferred when it's inquired, seems
a hit harsh.

Does this need (or would it benefit from) an interp?

Or should I add a regularization of this to my 56-page wishlist?

The regularization would be either
(1) Delete 7.1.11p2(9)(b)(ii) (my preference), or
(2) Prohibit reference to pointer or allocatable variables in
specification expressions (incompatible change).

More information about the J3 mailing list