J3/10-161 To: J3 From: Malcolm Cohen Subject: Final interp request 4. Date: 2010 June 01 ---------------------------------------------------------------------- NUMBER: TITLE: Finalising 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(t),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 finalisation 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 finalised - 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 finalised 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. Yes, the analysis is correct; use of vector subscripts is problematic when final subroutines are involved. ALTERNATIVE ANSWER: A. The analysis is correct but the situation was an inadvertant oversight: vector subscripts should be forbidden in conjunction with finalisation. Edits are supplied. EDITS: None. ALTERNATIVE EDITS: Add new constraint somewhere "Cnnnn A vector-subscripted array section shall not appear in a context that causes it to be finalized." SUBMITTED BY: Malcolm Cohen HISTORY: 10-nnn m192 Submitted ----------------------------------------------------------------------