Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
1 View

Protected type variables in modules with submodules

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
Highlighted
Beginner
1 View

NB: It also doesn't like it

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.   

 

0 Kudos
Highlighted
Valued Contributor III
1 View

You may want to submit

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

0 Kudos
Highlighted
Beginner
1 View

I've logged it with support.

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.

0 Kudos