https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127233

            Bug ID: 127233
           Summary: ASSOCIATED ignores element length
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mikael at gcc dot gnu.org
  Target Milestone: ---

The intrinsic ASSOCIATED returns true even for arrays with differing element
length, when arrays have matching span.  In the testcase, one array has a
substring whereas the other is full.

Testcase:

program prog
  implicit none
  character(len=:), allocatable, target :: c(:)
  c = ["abc", "def", "ghi", "jkl", "mno"]
  call sc(c, c, .true., 11)
  call sc(c(::2), c(::2), .true., 12)
  call sc(c(:)(1:2), c(:)(1:2), .true., 13)
  call sc(c(::2)(1:2), c(::2)(1:2), .true., 14)
  call sc(c(1:5:2), c(1:3), .false., 21)
  call sc(c(1:3), c(1:5:2), .false., 22)
  call sc(c(:)(1:2), c(:), .false., 23)
  call sc(c(:), c(:)(1:2), .false., 24)
  call sc(c(1:5:2)(1:2), c(1:3), .false., 25)
  call sc(c(1:3), c(1:5:2)(1:2), .false., 26)
  call sc(c(1:5:2), c(1:3)(1:2), .false., 27)
  call sc(c(1:3)(1:2), c(1:5:2), .false., 28)
contains
  subroutine sc(p, t, r, e)
    character(len=:), pointer, intent(in) :: p(:)
    character(len=*), target,  intent(in) :: t(:)
    logical, intent(in) :: r
    integer, intent(in) :: e
    call check(associated(p, t), r, e)
  end subroutine
  subroutine check(r, v, e)
    logical, intent(in) :: r, v
    integer, intent(in) :: e
    print *, r, v, (r.eqv.v ? "PASS" : "FAIL"), e
    !if (r .neqv. v) error stop e
  end subroutine
end program

output:
 T T PASS          11
 T T PASS          12
 T T PASS          13
 T T PASS          14
 F F PASS          21
 F F PASS          22
 T F FAIL          23
 T F FAIL          24
 F F PASS          25
 F F PASS          26
 F F PASS          27
 F F PASS          28

So cases 23 and 24 fail.

Reply via email to