- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your prompt response. I'll just have to drop the 'protected' qualification for now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This bug has been fixed for a future release.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Great - thanks. By future do you mean 16.x or 17.x ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
17.0 - it may or may not get fixed in a 16.0 update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Looks as if it will be fixed in 16.0 Update 3, scheduled for May.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page