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

Protected variables in modules with sub-modules

Simon_Geard
New Contributor I
378 Views
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
Steven_L_Intel1
Employee
378 Views

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.

0 Kudos
Simon_Geard
New Contributor I
378 Views

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

0 Kudos
Steven_L_Intel1
Employee
378 Views

This bug has been fixed for a future release.

0 Kudos
Simon_Geard
New Contributor I
378 Views

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

0 Kudos
Steven_L_Intel1
Employee
378 Views

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

0 Kudos
Steven_L_Intel1
Employee
378 Views

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

0 Kudos
Reply