Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26740 Discussions

Protected type variables in modules with submodules

Gripton__Adam
Beginner
101 Views

Hi,

This is a follow on question from https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/610969 in which a compiler bug was raised regarding the treatment of protected data in modules with submodules. I've installed Visual Fortran Compiler 18.0.3.210 [IA-32] and the code snippet from the original forum post does, indeed, now, compile. But when the protected variable is part of a TYPE, it still doesn't. To illustrate, I've amended the code from the original post to include a new variable within a TYPE definition:

 

module mymod
    implicit none
    integer, protected :: n  
    type mytype
        integer :: k
    end type mytype
    type (mytype), protected :: ty

    interface
        module subroutine set_n(i)
            integer, intent(in) :: i
        end subroutine set_n
        
        module subroutine set_k(i)
            integer, intent(in) :: i
        end subroutine set_k
    
    end interface  
end module mymod

submodule(mymod) mymod_i

contains
    module subroutine set_n(i)
        integer, intent(in) :: i
     n = i
    end subroutine set_n 
    
    module subroutine set_k(i)
        integer, intent(in) :: i
        ty%k = i
    end subroutine set_k
    
end submodule mymod_i

program test
    use mymod
    implicit none
    integer :: i

    i = 5
    call set_n(i)
    call set_k(i)
    print *,n
    print *,ty%k
end program test

 

When I try and compile this, the same error is raised as in the original post:

error #7986: A use associated object that has the PROTECTED attribute shall not appear in a variable definition context.   

Is this a further bug, or am I doing something wrong?

Many thanks in advance.

0 Kudos
3 Replies
Gripton__Adam
Beginner
101 Views

It also doesn't like it if you assign pointers to even standard-type variables that are protected but should be SUBMODULE-accessible:

module mymod
    implicit none
    integer, protected, target :: n  

    interface
        module subroutine set_n(i)
            integer, intent(in) :: i
    end subroutine set_n
    
        module subroutine set_pn
        end subroutine set_pn
        
    end interface  
end module mymod

submodule(mymod) mymod_i

contains
    module subroutine set_n(i)
        integer, intent(in) :: i
     n = i
    end subroutine set_n 
    
    module subroutine set_pn
        integer, pointer :: pn
        pn => n
    end subroutine set_pn
    
end submodule mymod_i

This produces the following compiler error:

error #7994: A use associated object that has the PROTECTED attribute shall not appear as a target in a pointer-assignment-stmt.   

 

FortranFan
Honored Contributor II
101 Views

You may want to submit support requests with Intel: https://supporttickets.intel.com/?lang=en-US

Gripton__Adam
Beginner
101 Views

I've logged it with support. I still think it's a compiler bug. In the original post from https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/610969 a very similar problem was identified as such and the compiler fixed accordingly.

Reply