The following code is modified from https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-fo....
module mymod implicit none integer, protected :: n integer, protected :: m(1) interface module subroutine set(i) integer, intent(in) :: i end subroutine set end interface end module mymod submodule(mymod) mymod_i contains module subroutine set(i) integer, intent(in) :: i n = i ! OK m = i ! OK m(1) = i ! ERROR #7986 call foo(m(1)) ! ERROR #7993 end subroutine set subroutine foo(x) integer, intent(out) :: x x = 10 end subroutine foo end submodule mymod_i program test use mymod implicit none integer :: i i = 5 call set_n(i) print *,n end program test
This fails to compile:
$ ifort test.f90 -o test
test.f90(18): error #7986: A use associated object that has the PROTECTED attriute shall not appear in a variable definition context. [M]
m(1) = i ! ERROR #7986
----^
test.f90(19): error #7993: A use associated object that has the PROTECTED attriute shall not appear as an actual argument if the associated dummy argument hasthe INTENT(OUT) or INTENT(INOUT) attribute. [M]
call foo(m(1)) ! ERROR #7993
-------------^
compilation aborted for test.f90 (code 1)
$ ifort --version
ifort (IFORT) 17.0.1 20161005
Copyright (C) 1985-2016 Intel Corporation. All rights reserved.
There was previously a compiler bug, now fixed, which prevented the "n" protected variable from being set in the submodule. It seems this problem still occurs for arrays.