Optimizing vectorized array operations

Before f2003, reallocation was not a possibility in the assignment, so I would say the semantics of that assignment+deallocation would have required the bounds of a to remain unchanged. With no pointers associated with a, no storage sequence requirements, etc., then I do think it would have been allowed for a compiler to do the shallow copy optimization to achieve the same ends. That is, the “as if” rule applies to that assignment the same as any other assignment. At least I can’t think of anything else in the language at that time what would have precluded that optimization. But if there are pointers and targets involved, or if storage sequence issues were involved, then such an optimization would not have been allowed because it would no longer satisfy the “as if” rule. As I said before, I don’t know of any compiler that actually did that kind of optimization, but at least as an academic question, I think it would have been allowed in some situations (where the compiler could verify that “as if” applied).

But after f2003, reallocation on assignment became possible, so the language needed to describe fully when c_f_pointer() results change, when the targets of pointers can change, when dummy argument aliases might occur, when bounds are transfered and when they aren’t, and so on. Those are all things that don’t just occur behinds the curtains, they are now things that have observable consequences within the fortran language. I think the language since f2003 does describe all of those situations fully. I mentioned the intent(in) and intent(inout) situations regarding pointer association as just one example of how careful the standard was in describing the standard behavior. However, this one common situation with assignment is not fully specified by the language. Since so many other similar situations involving allocatables, targets, and pointers are described fully in the language, one can assume that assignment case is just an oversight, that “only if” was intended, and that there are no special rules involving pointer associations or dummy argument aliases or bounds transfer that need to be considered. I think all of that should be clearly specified in the standard, not just assumed.