J3/10-161r1 To: J3 From: Malcolm Cohen Subject: Final interp request 4. Date: 2010 June 16 ---------------------------------------------------------------------- NUMBER: F08/0014 TITLE: Finalizing assignment to vector-subscripted object. KEYWORDS: Finalization DEFECT TYPE: Erratum STATUS: J3 consideration in progress QUESTION: Consider the program: Module m Type t1 Real c Contains Final :: f11 End Type Contains Subroutine f11(x) Type(t1),Intent(InOut) :: x(:) Print *,'f11 called' x%c = 0 ! (*) End Subroutine End Module Program q Use m Type(t1) :: x(10) = t1(0) x( [1,4,9] ) = t1(1.5) Print *,x End Program According to 6.5.3.2.2 Vector subscript, "An array section with a vector subscript shall not be ... argument associated with a dummy array that is defined or redefined ..." Therefore the program above is not standard-conforming; however it seems that deleting the assignment statement marked (*) would make the program standard-conforming. This seems to make final subroutines not useful when vector subscripts are involved; either the finalization doesn't do anything to the object in which case the vector subscript is allowed, or it does do something (like deallocation) in which case the vector subscript is disallowed. Also, since passing vector-subscripted objects as actual arguments is almost certainly going to pass a copy (and what's more a copy that won't be copied back), this results in something other than the actual entity being finalized - and this is possibly visible if pointers and targets are involved. Finally, these apparent violations of the standard are probably not going to be detected on many processors, resulting in silent wrong answers. At least if vector subscripted sections being finalized were rejected at compile time the user would stand a chance of avoiding these problems. Q. Is this analysis correct, and is this situation deliberate? ANSWER: A. The analysis is correct but the situation was an inadvertent oversight: vector subscripts should be forbidden in conjunction with finalization. An edit is supplied. ALTERNATIVE ANSWER: A. The analysis is correct. This should have been alleviated by allowing elemental procedures to modify vector-subscripted arguments. An edit is supplied. EDITS: [124:7+] Insert new constraint "C627a A vector-subscripted array section shall not appear in a context that causes it to be finalized." ALTERNATIVE EDITS: [124:7+] Insert new constraint "A vector-subscripted array section shall not be finalized by a nonelemental final subroutine." [124:7+] Insert new constraint "C627a A vector-subscripted array section shall not appear in a context that causes it to be finalized." [295:8] In 12.5.2.4p18, After "If" insert "the procedure is nonelemental and". SUBMITTED BY: Malcolm Cohen HISTORY: 10-161 m192 F08/0014 Submitted 10-161r1 m192 Revised answers and edits. ----------------------------------------------------------------------