J3/02-302 Date: October 25, 2002 To: J3 From: Rob James Subject: The magical "same value" behaviour of some intrinsics Introduction ------------ There are problems with passing structures that have allocatable components to some of the transformational intrinsics defined in section 13. The affected intrinsics are CSHIFT, MERGE, PACK, RESHAPE, SPREAD, and UNPACK. In the "Result Value" section of the descriptions of each of these intrinsics, it says that result either "has the same value as", or simply "is", an argument (or a subobject of an argument). There is no explanation of how the result gets this value, or how it could simply be the same object as the argument (which seems blatantly wrong), as the case may be. It just seems to be this way by The Magic of Fortran. The problem is that, for structure components that are allocatable, the simple bitwise copy semantics that are implied by these statements are simply wrong. Intrinsic assignment, on the other hand, is well defined for structures containing allocatable components. If it could be said that they are copied as if by intrinsic assignment, that would cover this situation. At first glance, saying they get the values "as if by intrinsic assignment" seems alright, at least for structure components that are allocatable. But is this really what is intended, especially in light of type-bound defined assignments that could be called during an intrinsic assignment? Depending on the semantics of those type-bound defined assignments, the result may not really have the "same value" as the argument. However, if that's alright, then the descriptions of the result values of these intrinsics can simply be changed to say that it is as if an intrinsic assignment had taken place. Otherwise, I think structures that have allocatable components need to be prohibited, as well as structures that have components whose types have a type-bound defined assignment. Either way, the bitwise semantics that are implied by these descriptions are just wrong. Proposed Edits -------------- These edits attempt to fix the descriptions of the result values of the affected intrinsics by referring to intrinsic assignment, rather than prohibiting derived types with allocatable components. Page and line numbers refer to the Committee Draft. To fix the description of CSHIFT: [306:14] Between "is" and "ARRAY", insert "assigned, as if by intrinsic assignment, the value of". [306:17] Replace "has a value equal to" with "is assigned, as if by intrinsic assignment, the value of". To fix the description of MERGE: [329:5] Replace with the following: <> If MASK is true, the result is assigned the value of TSOURCE as if by intrinsic assignment. Otherwise, the result is assigned the value of FSOURCE as if by intrinsic assignment. To fix the description of PACK: [336:1] Between "is" and "the", insert "assigned, as if by intrinsic assignment, the value of". [336:3] Replace "has the value" with "is assigned, as if by intrinsic assignment, the value of". To fix the description of RESHAPE: [341:5] Between "are" and "those", insert "assigned, as if by intrinsic assignment, the values of". To fix the description of SPREAD: [347:7] Replace "has a value equal to" with "is assigned, as if by intrinsic assignment, the value of". To fix the description of UNPACK: [352:4] Replace "has the value" with "is assigned, as if by intrinsic assignment, the value of". [352:5] Replace "has a value equal to" with "is assigned, as if by intrinsic assignment, the value of". [352:5] Replace "or to" with "or the value of".