I was playing around with a way to record log messages in an internal "file" (character variable) when I came upon a strange compiler notice. The following module does not compile, producing the error
error #7146: This object must not be used as an allocate-object in an allocate-stmt or deallocate-stmt in a PURE procedure or an internal procedure contained in a PURE procedure. [TEMP]
allocate(temp(2*size(this%buffer)), mold = this%buffer)
Simply removing the associate construct gets rid of the error. Allocation and internal file I/O should both be fine in PURE procedures, right?
module logmod implicit none private type, public :: logger private character(128), allocatable :: buffer(:) integer :: idx = 1 contains procedure, public, pass(this) :: info end type logger contains pure subroutine info(this, msg) class(logger), intent(inout) :: this character(*), intent(in) :: msg ! Temporary buffer character(:), allocatable :: temp(:) ! This unused association causes error #7146 associate(i => this%idx) ! Check buffer status if (.not. allocated(this%buffer)) then ! Allocate and fill buffer of initial size 100 allocate(this%buffer(100)) this%buffer = '' elseif (this%idx == size(this%buffer)) then ! Increase buffer size allocate(temp(2*size(this%buffer)), mold = this%buffer) temp(1:size(this%buffer)) = this%buffer call move_alloc(temp, this%buffer) endif write(this%buffer(this%idx), '(a)') msg this%idx = this%idx + 1 end associate end subroutine end module