gfortran 12, 13, 14, and 15 all reject the source allocation of a pure
function result object's allocatable component with the message "Bad
allocate-object at (1) for a PURE procedure". Removing "pure"
eliminates the error. Alternatively, removing the separate procedure
interface also eliminates the error. Eliminating the explicit
"result" clause generates a different error shown below.
% cat source-allocate-pure-function-result-component.f90
module test_m
implicit none
type test_t
integer, allocatable :: i
end type
interface
pure module function construct_test() result(test)
implicit none
type(test_t) test
end function
end interface
contains
module procedure construct_test
allocate(test%i, source = 0)
end procedure
end module
% gfortran -c source-allocate-pure-function-result-component.f90
source-allocate-pure-function-result.f90:17:20:
17 | allocate(test%i, source = 0)
| 1
Error: Bad allocate-object at (1) for a PURE procedure
% gfortran --version
GNU Fortran (GCC) 15.0.1 20250412 (experimental)
If the separate "result" clause is eliminated and the procedure name
is therefore the result name ("test"), then the error message changes
to
17 | allocate(test%i, source = 0)
| 1
Error: ‘test’ at (1) is not a variable