This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/28923] New: Bad triplet interpretation in initialization


The following program:

real, dimension(3,3), parameter :: a=reshape ((/(i, i = 1,9)/),(/3,3/))
real, dimension(2,3) :: b=a(:2:-1,:)
real, dimension(2,3) :: c=a(3:2:-1,:)
print *, b
print *, c
end

compiles with gfortran and gives:

   3.000000       2.000000       6.000000       5.000000       9.000000      
8.000000    
   3.000000       2.000000       6.000000       5.000000       9.000000      
8.000000    

i.e., b=a(:2:-1,:) is interpreted as c=a(3:2:-1,:) instead of giving:

real, dimension(2,3) :: b=a(:2:-1,:)
                          1
Error: Array assignment at (1) has different sizes (6/0)

as required by the following first and last paragraphs (draft f2003):

> 6.2.2.3.1 Subscript triplet
> 
> A subscript triplet designates a regular sequence of subscripts
> consisting of zero or more subscript values.  The third expression in the
> subscript triplet is the increment between the subscript values and is
> called the stride.  The subscripts and stride of a subscript triplet are
> optional.  An omitted first subscript in a subscript triplet is
> equivalent to a subscript whose value is the lower bound for the array
> and an omitted second subscript is equivalent to the upper bound.  An
> omitted stride is equivalent to a stride of 1.
> 
> The stride shall not be zero.
> 
> When the stride is positive, the subscripts specified by a triplet form a
> regularly spaced sequence of integers beginning with the first subscript
> and proceeding in increments of the stride to the largest such integer
> not greater than the second subscript; the sequence is empty if the first
> subscript is greater than the second.  
> 
> ...
> 
> When the stride is negative, the sequence begins with the first subscript
> and proceeds in increments of the stride down to the smallest such
> integer equal to or greater than the second subscript; the sequence is
> empty if the second subscript is greater than the first.

Note that:

real, dimension(3,3) :: a
real, dimension(2,3) :: b
a=1
b=a(:2:-1,:)
print *, b
end

gives correctly:

b=a(:2:-1,:)
1
Error: different shape for Array assignment at (1) on dimension 1 (2/0)

Dominique


-- 
           Summary: Bad triplet interpretation in initialization
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dominiq at lps dot ens dot fr
 GCC build triplet: gcc version 4.2.0 20060826 (experimental)
GCC target triplet: powerpc-apple-darwin7


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28923


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]