- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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?
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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?
Enlace copiado
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Something similar was already mentioned here back in 2021:
https://fortran-lang.discourse.group/t/assumed-rank-arrays/1049/7
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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?
- Suscribirse a un feed RSS
- Marcar tema como nuevo
- Marcar tema como leído
- Flotar este Tema para el usuario actual
- Favorito
- Suscribir
- Página de impresión sencilla