08-186r1 To: J3 From: Stan Whitlock Subject: New answer for F2003 interp F03/0112 Date: 2008 May 15 ---------------------------------------------------------------------- NUMBER: F03/0112 TITLE: attributes allowed for dummy arguments in defined assignments KEYWORDS: defined assignment, dummy argument, attributes DEFECT TYPE: Erratum STATUS: J3 consideration in progress DISCUSSION: It seems the standard is quite loose in allowing various attributes declared for the dummy arguments used in a defined assignment (7.4.1.4). In particular, attributes such as POINTER and ALLOCATABLE can be declared for dummy arguments in the defined assignment. However the interpretations on their declarations need to be clarified. Consider the follow subroutines (assuming a derived type DT already defined) 1. POINTER/ALLOCATABLE on the second dummy argument interface ASSIGNMENT (=) subroutine defAssgn1 (dt1, dt2) type(DT), intent(out) :: dt1 type(DT), POINTER, intent(in) :: dt2 end subroutine end interface In 12.3.2.1.2 [263:10-12], the standard says the following "A defined assignment is treated as a reference to the subroutine, with the left-hand side as the first argument and the right-hand side enclosed in parentheses as the second argument." This statement seems to prohibit the use of subroutine defAssgn1 for defined assignment since a pointer enclosed in parentheses refers to its associated target not the pointer itself, as indicated by rules in 7.1.4.1 [123:39-124:3]. 2. POINTER/ALLOCATABLE on the first dummy argument interface ASSIGNMENT (=) subroutine defAssgn2 (dt1, dt2) type(DT), POINTER, intent(out) :: dt1 type(DT), intent(in) :: dt2 end subroutine end interface There are no rules in the standard disallow this declaration. However the use of POINTER/ALLOCATABLE attributes on the first dummy argument is very doubtful. Since POINTER/ALLOCATABLE attributes don't disambiguate generic declarations(16.2.3), their use will prevent the normal declarations of defined assignments, wherein dt1 is declared without POINTER or ALLOCATABLE attribute. QUESTIONS: 1. Are POINTER and ALLOCATABLE attributes allowed for the second dummy argument in defined assignment? 2. Are POINTER and ALLOCATABLE attributes allowed for the first dummy argument in defined assignment? ANSWER: Yes to both questions. The standard places very few restrictions on the arguments to defined assignment subroutines: [263:6...] Each of these subroutines shall have exactly two dummy arguments. Each argument shall be nonoptional. The first argument shall have INTENT (OUT) or INTENT (INOUT) and the second argument shall have INTENT (IN). ... Preventing the first argument from having the POINTER attribute violates F90. Such a restriction for the second argument has no effect since the right argument is treated as an expression enclosed in parentheses which would have neither attribute but it does no harm. An edit is provided. EDITS: In section 12.3.2.1.2 of 04-007, second paragraph, at the end of the third sentence [263:8], after "INTENT (IN)", insert "and shall not have the ALLOCATABLE attribute". SUBMITTED BY: Jim Xia HISTORY: 08-120 m183 F03/0112 Submitted 08-120r1 m183 Create answer 08-120r2 m183 Passed by J3 meeting 08-163 m184 Failed J3 letter ballot 08-141 08-186 m184 Another answer