To: J3 08-120r2 From: Jim Xia/Stan Whitlock Subject: Interpretation: attributes allowed for dummy arguments in defined assignments Date: 2008 February 15 NUMBER: F03/0112 TITLE: attributes allowed for dummy arguments in defined assignments KEYWORDS: defined assignment, dummy argument, attributes DEFECT TYPE: Clarification STATUS: Passed by J3 ballot 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: [363: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. EDITS: None NOTE: A future standard should disallow the POINTER and ALLOCATABLE attributes on the second argument to defined assignment subroutines. SUBMITTED BY: Jim Xia HISTORY: 08-120 m183 F03/0112 Submitted 08-120r1 m183 Create answer 08-120r2 m183 Passed by J3 meeting