EDIT: This has been marked as a duplicate of a question about using array elements to iterate a do loop. A similar question to be sure, but you can read the answers and not see anything about using non-array members of derived types. Even though the logic might be the same, it is not at all spelled out for anyone who doesn't already realize that the same logic applies. So I think this is a distinct question.
This code will not compile under gfortran (version 5.2.0). The compiler returns an "unclassifiable statement" error where marked:
module stuff
type foo
integer :: bar
contains
procedure :: iterator
end type foo
contains
subroutine iterator(stuff_inst)
class(foo) :: stuff_inst
integer :: local_bar
do stuff_inst%bar=1,10 ! <--- error
print *, stuff_inst%bar
enddo
end subroutine
end module stuff
This code compiles just fine and, with a driving program, runs OK too:
module stuff
type foo
integer :: bar
contains
procedure :: iterator
end type foo
contains
subroutine iterator(stuff_inst)
class(foo) :: stuff_inst
integer :: local_bar
do local_bar=1,10 ! <--- no error
stuff_inst%bar = local_bar ! <--- no error
print *, stuff_inst%bar
enddo
end subroutine
end module stuff
Could someone tell me the specific problem? Is it not legal to use derived type members in a do loop iteration? That's all I can think of, but I have searched and can't find any rule to that effect.