On Thu, Jul 09, 2015 at 08:59:08PM +0200, Andre Vehreschild wrote: > Hi Steve, > > Thanks for your knowledge. Can you support your statement that an allocatable > function has to return an allocated object by a part of the standard? I > totally agree with you that this code is ill-designed, but IMO is it not the > task of the compiler to address ill design. The compiler has to comply to the > standard and the standard allows allocatable objects to be unallocated. So > why has the result of a function be allocated always? > > Regards, > Andre >
I think the following excerpts from F2008 are the relevant clauses, especially the 2nd to last sentence in the excerpt from 12.6.2.2. ! 12.5.3 ! ! When execution of the function is complete, the value of ! the function result is available for use in the expression ! that caused the function to be invoked. ! ! 12.6.2.2 ! ! If RESULT appears, the name of the result variable of the ! function is result-name and all occurrences of the function ! name in execution-part statements in its scope refer to the ! function itself. If RESULT does not appear, the name of the ! result variable is function-name and all occurrences of the ! function name in execution-part statements in its scope are ! references to the result variable. The characteristics (12.3.3) ! of the function result are those of the result variable. On ! completion of execution of the function, the value returned is ! that of its result variable. If the function result is a pointer, ! the shape of the value returned by the function is determined by ! the shape of the result variable when the execution of the function ! is completed. If the result variable is not a pointer, its value ! shall be defined by the function. If the function result is a ! pointer, on return the pointer association status of the result ! variable shall not be undefined. -- Steve