J3/13-278
To: J3
From: Malcolm Cohen
Subject: Interp f08/95 on PRESENT
Date: 2013 June 26
----------------------------------------------------------------------
NUMBER: F08/0095
TITLE: Is PRESENT allowed in specification and constant expressions
KEYWORD: PRESENT, optional dummy argument
DEFECT TYPE: Erratum
STATUS: J3 consideration in progress
QUESTION:
Q1. Consider
Subroutine s1(a)
Integer,Optional :: a
Logical,Parameter :: x = Present(a)
Print *,x
End Subroutine
Does this program unit conform to the standard?
7.1.12 item (4) permits
"a specification inquiry where each designator or function argument
is ...
(b) a variable whose properties inquired about are not
(i) assumed,
(ii) deferred, or
(iii) defined by an expression that is not a constant
expression,"
PRESENT is a specification inquiry (because it is an intrinsic inquiry
function), and the standard does not say that the "presence" of an
optional dummy argument is an assumed or deferred attribute, and it
does not appear to be "defined by an expression" either.
On the other hand, the standard does not say anything about what kind
of property the presence is.
Q2. Consider
Subroutine s2(a)
Integer,Optional :: a
Real x(Merge(2,3,Present(a)))
If (Present(a)) Then
x = [ 1,2,a ]
Else
x = [ 1,2 ]
End If
Print *,x
End Subroutine
Does this program unit conform to the standard? It appears to satisfy
the rules for specification expression, similarly to how it satisfies
the rules for a constand expression, but then the standard is silent
as to what sort of property "presence" is...
Q3. Consider
Subroutine s3(a)
Character(*),Optional :: a
Real x(Len(a))
Print *,Size(x)
End Subroutine
Does this program unit conform to the standard? Using the same
reasoning as Q1 and Q2, it appears to conform, but if A is absent,
LEN(A) is not permitted by 12.5.2.12.
ANSWER:
A1. Program unit S1 was not intended to conform to the standard.
An edit is provided to clarify that this is not valid.
A2. Program unit S2 was intended to conform to the standard.
An edit is provided to clarify that this is valid.
A3. This program was not intended to conform to the standard.
An edit is provided to clarify that this is not valid.
EDITS to 10-007r1:
[150:24] 7.1.11p2, item (9)(b)
after "variable" insert ",that is not an optional dummy argument, ".
{Prevent specification enquiries on optional dummy arguments.}
[150:27+] 7.1.11p2, after item (9) entirely,
insert "(9a) a specification inquiry that is a constant expression,
(9b) a reference to the intrinsic function PRESENT,"
{Allow inquiries on optional dummy arguments that will not violate the
rules in 12.5.2.12 when the dummy is absent,
and allow PRESENT to be used.}
[150:37] 7.1.11p4, item (1)
after "intrinsic inquiry function" insert "other than PRESENT".
{Remove PRESENT from list of specification inquiries, this fixes
constant expressions.}
SUBMITTED BY: Malcolm Cohen/Van Snyder
HISTORY: m201 13-nnn Submitted
----------------------------------------------------------------------