- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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?
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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?
コピーされたリンク
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
Something similar was already mentioned here back in 2021:
https://fortran-lang.discourse.group/t/assumed-rank-arrays/1049/7
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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?