Compiler bug with associate construct

Compiler bug with associate construct

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

 

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Best Reply

Hello,

Looks like an ifort defect.  I'll report this to the developers.

Thanks,

patrick

Quote:

Patrick Kennedy (Intel) wrote:

Hello,

Looks like an ifort defect.  I'll report this to the developers.

Thanks,

patrick

Thanks!

This has been reported to the developers.  I'll keep this thread update with any news.  Tracking #DPD200254361

patrick

Resolved in Composer XE 2013 SP1 Update 3:

 

[U507066]$ ifort -V
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0.3.174 Build 20140422
Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.

[U507066]$ ifort U507066.f90 -c
[U507066]$

 

Patrick

Leave a Comment

Please sign in to add a comment. Not a member? Join today