Skip to content

Commit

Permalink
auto allocate: update for GCC-14 more correct behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed May 21, 2024
1 parent 2652ead commit d72039d
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions test/array/auto_allocate.f90
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ program auto_allocate
print *, "OK: auto-allocate fixed allocate first"

!> if lhs(:) = rhs and shape(lhs) /= shape(rhs) behavior is UNDEFINED.
!> Ifx/ifort 2023.0 newly detect with -CB -check bounds option.
!> oneAPI 2023.0 newly detect with -CB -check bounds option.
A(:) = [9,8]
if (size(A) /= 2) error stop '(:) syntax smaller'
if (any(A /= [9,8])) then
Expand All @@ -58,21 +58,25 @@ program auto_allocate
endif
print *, "OK: auto-allocate (:) syntax smaller"

E(:) = [1,2,3]
if (size(E) /= 4) error stop 'allocate() (:) syntax small'
if (any(E(:3) /= [1,2,3])) then
write(stderr,*) 'allocate() (:) assign small: E=', E(:3)
error stop
endif
print *, "OK: auto-allocate (:) syntax small"
!> new for Gfortran 14
!! Fortran runtime error: Array bound mismatch for dimension 1 of array 'e' (4/3)
! E(:) = [1,2,3]
! if (size(E) /= 4) error stop 'allocate() (:) syntax small'
! if (any(E(:3) /= [1,2,3])) then
! write(stderr,*) 'allocate() (:) assign small: E=', E(:3)
! error stop
! endif
! print *, "OK: auto-allocate (:) syntax small"

E(:) = [5,4,3,2]
if (size(E) /= 4) error stop 'allocate() (:) syntax: big'
if (any(E /= [5,4,3,2])) then
write(stderr,*) 'allocate() (:) assign: big: E=', E
error stop
endif
print *, "OK: auto-allocate (:) syntax big"
!> new for Gfortran 14
!! Fortran runtime error: Array bound mismatch for dimension 1 of array 'e' (4/5)
! E(:) = [5,4,3,2,1]
! if (size(E) /= 5) error stop 'allocate() (:) syntax: big'
! if (any(E /= [5,4,3,2,1])) then
! write(stderr,*) 'allocate() (:) assign: big: E=', E
! error stop
! endif
! print *, "OK: auto-allocate (:) syntax big"

!> (lbound:ubound)
! A(1:3) = [4,5,6]
Expand Down

0 comments on commit d72039d

Please sign in to comment.