Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29282 Discussions

syntax error: logical expression in sourced allocation

Ferdinand_T_
New Contributor II
1,086 Views

Hello,

today ifort 14.0.1 got me confused with the followign syntax error where I think I wrote legal code:

[fortran]

program p
    implicit none
    logical, allocatable :: flag
 
    ! allocation and assignment from logical expression
    allocate(flag)
    flag = .true. .or. .false.            ! OK
 
    ! sourced allocation from logical expression
    allocate(flag, source = (.true. .or. .false.))    ! OK
    allocate(flag, source =  .true. .or. .false. )    ! ERROR
 
end program

[/fortran]

Output:


error #5082: Syntax error, found '.' when expecting one of: * ) :: , <END-OF-STATEMENT> ; . (/ + - : ] /) ' ** / // > .LT. < ...
    allocate(flag, source = .true. .or. .false.)
---------------------------------------^

Just out of curiosity: can somebody comment on this?

Best regards
Ferdinand

0 Kudos
6 Replies
Steven_L_Intel1
Employee
1,086 Views

I think that's legal and will ask the developers to fix this.

0 Kudos
Intel_C_19
Beginner
1,086 Views

 

I add a logical :: a,b in the statements, and change line 11 into "allocate(flag, source = a.or.b )"

then I get:

error #6866: Dotted string neither a defined operator nor a structure component [OR]
allocate(flag, source = a.or.b ) ! ERROR
-------------------------------^
error #8155: In an ALLOCATE statement the source expression in SOURCE= or MOLD= specifiers must be of the same type and kind type parameters as the object being allocated.
allocate(flag, source = a.or.b ) ! ERROR

seems the compiler forget what is "or" here.....

 

 

 

 

 

0 Kudos
Izaak_Beekman
New Contributor II
1,086 Views

Perhaps I missed something, but don't you need to deallocate flag before reallocating it? This is certainly the case for allocatble arrays, and I beleive it applies to allocatable scalars as well. (Although, this isn't explicitly stated to be true for scalars in Modern Fortran Explained... AFAICT)

0 Kudos
Ferdinand_T_
New Contributor II
1,086 Views

Thanks, Steve.

@ heylouis,
Any logical operation (not only .or.) raises an error. Only a logical primary or a parenthesed expression is currently accepted in the source.

0 Kudos
Steven_L_Intel1
Employee
1,086 Views

Izaak, yes, the code as shown would be an invalid double (or even triple) allocation, but the code does demonstrate the problem reported.

0 Kudos
Steven_L_Intel1
Employee
1,086 Views

This problem has been fixed for a future release.

0 Kudos
Reply