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

PURE + INTENT(IN) + Type-Bound Procedures

John4
Valued Contributor I
430 Views

Hi,

In the code below, the use of the PURE attribute in the subroutine getDummyLines seems to trigger a variable definition context error (error #7138: This dummy-arg appears in a 'defining' context in a PURE procedure or in an internal procedure contained in a PURE procedure). Without the PURE attribute in the subroutine getDummyLines, the error goes away. The error also goes away by calling getDummyIndex instead of the type-bound procedure (this%getDummyIndex)... So, is there any kind of new restriction to PURE procedures in the Fortran 2003 standard, is it just the same issue with CLASS and INTENT, reported before (DPD200150651)? Or is it something new?

[fortran]module pure_intent

    implicit none
    private
    save

    type, abstract, public :: SomeClass
        integer, allocatable, private :: dummy(:)
    contains
        procedure :: getDummyIndex
        procedure :: getDummyLines
    end type

contains
    !----------------------------------------------------------------------------------------------
    pure subroutine getDummyIndex(this, header, idx)
        logical :: status
        class(SomeClass), intent(IN) :: this
        character(:), allocatable, intent(INOUT) :: header
        integer, intent(OUT) :: idx

    continue
        idx = 0

        if (.NOT. ALLOCATED(this%dummy)) return
    end subroutine

    !----------------------------------------------------------------------------------------------
    pure subroutine getDummyLines(this, header, lines) !The PURE attribute triggers an error here
        class(SomeClass), intent(IN) :: this
        character(*), intent(IN) :: header
        character(:), allocatable, intent(OUT) :: lines(:)
        integer :: idx
        character(:), allocatable :: header_

    continue
        if (.NOT. ALLOCATED(this%dummy)) return

        header_ = TRIM(ADJUSTL(header))

        call this%getDummyIndex(header_, idx)
        !call getDummyIndex(this, header_, idx)
    end subroutine

end module pure_intent
[/fortran]

0 Kudos
1 Solution
Steven_L_Intel1
Employee
430 Views
I expect this issue to be fixed in our November release.

View solution in original post

0 Kudos
3 Replies
jimdempseyatthecove
Honored Contributor III
430 Views
John,

I don't delve much in this area, so I may be wrong on my read.

On line 5 of your sample you have "save". This is in the module data/declaration area prior to the "contains" section. What I do not know is if this "save" attribute carries on into the contained subroutines. If it does, then the local variables are "save" variables. (e.g. status in getDummyIndex and idx in getDummyLines)

If these are "save" variables, then calling these subroutines have a side effect. i.e. not pure.
You should (? assumption on my part) be able to have "save" in pure provided that it is entirely enclosed (hidden) in the pure function. Since these two pure functions are nested, and the save is associated with the module (as opposed to individual subroutines) I do know if the compiler may have issue with this.

Try commenting on the save on line 5
If that works (but you need save), then try adding save inside each subroutine.
(or wait for Steve to reply with full analysis)

Jim Dempsey
0 Kudos
Steven_L_Intel1
Employee
430 Views
The module-level SAVE does not affect the contained routines, and it is not relevant to this issue.

I think this is simply a compiler bug. It is one that was also reported to us about a week ago - issue ID is DPD200156891.
0 Kudos
Steven_L_Intel1
Employee
431 Views
I expect this issue to be fixed in our November release.
0 Kudos
Reply