Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
2 Views

Protected variables in modules with sub-modules

module mymod
    implicit none
    integer, protected :: n  

    interface
        module subroutine set_n(i)
            integer, intent(in) :: i
        end subroutine set_n
    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	
end submodule mymod_i

program test
    use mymod
    implicit none
    integer :: i

    i = 5
    call set_n(i)
    print *,n
end program test

The above code fails to compile with the error

ifort tc.f90
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.2.180 Build 20160204
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

tc.f90(17): error #7986: A use associated object that has the PROTECTED attribute shall not appear in a variable definition context.  
                n = i
----------------^
compilation aborted for tc.f90 (code 1)

Is it possible to protect module data and still use the sub-module structure? If I had written this in just a single module there would not have been a problem. Shouldn't a sub-module's procedures have the same access rights to module data as if they were part of the module?

Thanks.

0 Kudos
6 Replies
Highlighted
2 Views

I think this is a compiler

I think this is a compiler bug. A submodule does not "use associate" from its parent (and in fact is not allowed to). I will report it to the developers.

Retired 12/31/2016
0 Kudos
Highlighted
New Contributor I
2 Views

Thanks for your prompt

Thanks for your prompt response. I'll just have to drop the 'protected' qualification for now.

0 Kudos
Highlighted
2 Views

This bug has been fixed for a

This bug has been fixed for a future release.

Retired 12/31/2016
0 Kudos
Highlighted
New Contributor I
2 Views

Great - thanks. By future do

Great - thanks. By future do you mean 16.x or 17.x ?

0 Kudos
Highlighted
2 Views

17.0 - it may or may not get

17.0 - it may or may not get fixed in a 16.0 update.

Retired 12/31/2016
0 Kudos
Highlighted
2 Views

Looks as if it will be fixed

Looks as if it will be fixed in 16.0 Update 3, scheduled for May.

Retired 12/31/2016
0 Kudos