- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
while compiling some "legacy code" containing statement functions,
(see example below), I see ifort v12 showing warnings of the type:
ifort_scope.f90(18): warning #7261: For standard Fortran 2003, a variable in a statement function expression must be a dummy argument of the statement functionor a variable that is accessible in the same scoping unit as the statement function (R1226.5). [NIBITS]
ibits (invar,ibpos,icovr) = IAND (ISHFT(invar,-ibpos),nibits(icovr))
----------------------------------------------------------^
I looked into the drafts of F2003 and F2008 but did not find anything related to R1226
enlightening me. Can anybody tell me what exactly is wrong, and why nibits is out of scope?
[fortran]module ifort_scope implicit none integer :: nibits(31) & ! masking constants (2^j -1 , j=1,..31) = (/ 1, 3, 7, 15, & 31, 63, 127, 255, & 511, 1023, 2047, 4095, & 8191, 16383, 32767, 65535, & 131071, 262143, 524287, 1048575, & 2097151, 4194303, 8388607, 16777215, & 33554431, 67108863, 134217727, 268435455, & 536870911, 1073741823, 2147483647 /) contains subroutine foo () integer :: ibits, invar, ibpos, icovr ! Statement function ibits (invar,ibpos,icovr) = IAND (ISHFT(invar,-ibpos),nibits(icovr)) print *, ibits (1,2,3) end subroutine foo end module ifort_scope [/fortran]
Regards,
Harald
while compiling some "legacy code" containing statement functions,
(see example below), I see ifort v12 showing warnings of the type:
ifort_scope.f90(18): warning #7261: For standard Fortran 2003, a variable in a statement function expression must be a dummy argument of the statement functionor a variable that is accessible in the same scoping unit as the statement function (R1226.5). [NIBITS]
ibits (invar,ibpos,icovr) = IAND (ISHFT(invar,-ibpos),nibits(icovr))
----------------------------------------------------------^
I looked into the drafts of F2003 and F2008 but did not find anything related to R1226
enlightening me. Can anybody tell me what exactly is wrong, and why nibits is out of scope?
[fortran]module ifort_scope implicit none integer :: nibits(31) & ! masking constants (2^j -1 , j=1,..31) = (/ 1, 3, 7, 15, & 31, 63, 127, 255, & 511, 1023, 2047, 4095, & 8191, 16383, 32767, 65535, & 131071, 262143, 524287, 1048575, & 2097151, 4194303, 8388607, 16777215, & 33554431, 67108863, 134217727, 268435455, & 536870911, 1073741823, 2147483647 /) contains subroutine foo () integer :: ibits, invar, ibpos, icovr ! Statement function ibits (invar,ibpos,icovr) = IAND (ISHFT(invar,-ibpos),nibits(icovr)) print *, ibits (1,2,3) end subroutine foo end module ifort_scope [/fortran]
Regards,
Harald
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem with those rule references in the error messages is that they are specific to one version of the standard. The error message is referring to Fortran 90, R1226 and the fifth constraint.
In Fortran 2003, this is C1265 on page 285: "Each variable reference in scalar-expr may be either a reference to a dummy argument of the statement function or a reference to a variable accessible in the same scoping unit as the statement function statement."
Fortran 2008 spells out things somewhat differently and drops the wording about "accessible in the same scoping unit" (C1271)
My guess is that the compiler is complaining that NBITS is declared in a host scoping unit, though it is certainly accessible in foo. I think this is a compiler bug and will report it. But I also would suggest you rewrite your ibits as a module or contained function. Is there a reason you don't like the intrinsic definition?
Issue ID is DPD200179255.
In Fortran 2003, this is C1265 on page 285: "Each variable reference in scalar-expr may be either a reference to a dummy argument of the statement function or a reference to a variable accessible in the same scoping unit as the statement function statement."
Fortran 2008 spells out things somewhat differently and drops the wording about "accessible in the same scoping unit" (C1271)
My guess is that the compiler is complaining that NBITS is declared in a host scoping unit, though it is certainly accessible in foo. I think this is a compiler bug and will report it. But I also would suggest you rewrite your ibits as a module or contained function. Is there a reason you don't like the intrinsic definition?
Issue ID is DPD200179255.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the explanation and confirmation of my understanding of scoping units.
I was afraid there might be something very obscure with statement functions.
(I haven't actively used them for years).
The reference to the constraint in the warning was confusing, in particular as it
explicitly refers to F2003, and F2003 was requested.
Regarding the use of statement functions: I use a foreign module, which
is why I wrote "legacy code". I'll try to convince the authors to change
the code.
Thanks,
Harald
I was afraid there might be something very obscure with statement functions.
(I haven't actively used them for years).
The reference to the constraint in the warning was confusing, in particular as it
explicitly refers to F2003, and F2003 was requested.
Regarding the use of statement functions: I use a foreign module, which
is why I wrote "legacy code". I'll try to convince the authors to change
the code.
Thanks,
Harald
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The diagnostic is actually correct for Fortran 90, which had a "same scope" restriction. Fortran 95 and later revisions gradually relaxed restrictions here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This has been fixed for a future release. The diagnostic will be issued only if you ask for F90 standards checking.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page