Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29578 ディスカッション

Compiler bug: Error #7617 on assigning function result in pure subroutine contained in pure function

Oliver_Zick
初心者
118件の閲覧回数

Hi all,

 

the compiler reports

error #7617: This host associated object appears in a 'defining' context in a PURE procedure or in an internal procedure contained in a PURE procedure. 

when a pure (or elemental) subroutine contained in a pure (or elemental) functions assigns a value to the functions result variable:

  pure integer(4) function Pure_func() result(res)
  
    call Assign_res()
  
  contains
  
    ! Neither works for pure nor elemental functions
    ! Compiler reports error #7617: This host associated object appears in a 'defining' context in a PURE procedure or in an internal procedure contained in a PURE procedure.   [RES]
    pure subroutine Assign_res()
      ! This should be possible
      res = 10
    end subroutine
  
  end function

 

When the function is transformed into a subroutine - it's working fine:

 

  ! Works for subroutine even when declared as elemental
  elemental subroutine Pure_sub(res)
  
    integer(4), intent(out) :: res
    
    call Assign_res()
    
  contains
  
    pure subroutine Assign_res()
      res = 10
    end subroutine
  
  end subroutine

 

I haven't found any suitable information in the Developers documentation for limitations regarding host association in this particular scenario (hope, I didn't miss them.)

 

Is this intended and by design or a compiler bug?

1 解決策
Mark_Lewy
高評価コントリビューター I
88件の閲覧回数

It's not a bug, see C1594 in J3/SD-007 (Fortran 2018 Interpretation document):

res is host-associated from Pure_func, and res = 10 puts it in a defining context. Since Assign_res is pure and is also contained in a pure procedure, this violates the purity rules.

It should really be applying the same logic to the code that compiles, which could be considered an extension to the standard.  I wonder if compiling it with standards warning on diagnoses this?

元の投稿で解決策を見る

2 返答(返信)
Oliver_Zick
初心者
110件の閲覧回数

Something similar was already mentioned here back in 2021:

https://fortran-lang.discourse.group/t/assumed-rank-arrays/1049/7

Mark_Lewy
高評価コントリビューター I
89件の閲覧回数

It's not a bug, see C1594 in J3/SD-007 (Fortran 2018 Interpretation document):

res is host-associated from Pure_func, and res = 10 puts it in a defining context. Since Assign_res is pure and is also contained in a pure procedure, this violates the purity rules.

It should really be applying the same logic to the code that compiles, which could be considered an extension to the standard.  I wonder if compiling it with standards warning on diagnoses this?

返信