I am trying the following code, which simply adds two array constructors to get a one-dimensional array. However, depending on whether one is used in these expressions (outside implied DO loop), I get incorrect results with gfortran-5.3 for (1), (3), and (6). On the other hand, ifort-14.0 and Sun fortran 8.7 give correct results for all cases. Strangely, if I try a similar but more complicated expression, even Sun fortran starts to behave strangely (i.e., it gets frozen during compilation...) So I am wondering whether I am using some wrong or dangerous syntax in these expressions. Any idea...? (BTW, if I leave only one constructor between the two, they always work as expected.)
program main
implicit none
integer :: k
integer, dimension(2), parameter :: zero = [0,0], one = [1,1]
integer, parameter :: N = 1
print *, [ one, ( zero, k=1,N) ] + [ ( zero, k=1,N), one ] !! (1)
print *, [ [1, 1], ( zero, k=1,N) ] + [ ( zero, k=1,N), [1, 1] ] !! (2)
print *, [ one, ([0, 0],k=1,N) ] + [ ([0, 0],k=1,N), one ] !! (3)
print *, [ [1, 1], ([0, 0],k=1,N) ] + [ ([0, 0],k=1,N), [1, 1] ] !! (4)
print *, [ 1, 1, ( 0, 0, k=1,N) ] + [ ( 0, 0, k=1,N), 1, 1 ] !! (5)
print *, [ one, ( 0, 0, k=1,N) ] + [ ( 0, 0, k=1,N), one ] !! (6)
print *, [ (one, k=1,1), (zero, k=1,N) ] + [ (zero, k=1,N), (one, k=1,1) ] !! (7)
endprogram
Results with ifort14.0 and Sun Fortran 8.7:
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
Results with gfortran-5.3:
1 1 0 1
1 1 1 1
1 1 0 1
1 1 1 1
1 1 1 1
1 1 0 1
1 1 1 1