Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Compiler bug with associate construct

sfranzen
Beginner
1,152 Views

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


 

0 Kudos
1 Solution
pbkenned1
Employee
1,152 Views

Hello,

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

Thanks,

patrick

View solution in original post

0 Kudos
4 Replies
pbkenned1
Employee
1,153 Views

Hello,

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

Thanks,

patrick

0 Kudos
sfranzen
Beginner
1,152 Views

Patrick Kennedy (Intel) wrote:

Hello,

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

Thanks,

patrick

Thanks!

0 Kudos
pbkenned1
Employee
1,152 Views

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

patrick

0 Kudos
pbkenned1
Employee
1,152 Views

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

0 Kudos
Reply