view gcc/testsuite/gfortran.dg/iso_c_binding_c_loc_char_1.f03 @ 144:8f4e72ab4e11

fix segmentation fault caused by nothing next cur_op to end
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 21:23:56 +0900
parents 04ced10e8804
children
line wrap: on
line source

! { dg-do compile }
! PR 38536 - don't reject substring of length one
! Original test case by Scot Breitenfeld
SUBROUTINE test(buf, buf2, buf3, n)
  USE, INTRINSIC :: ISO_C_BINDING
  IMPLICIT NONE
  CHARACTER(LEN=*), INTENT(INOUT), TARGET :: buf
  INTEGER, INTENT(in) :: n
  CHARACTER(LEN=*), INTENT(INOUT), DIMENSION(1:2), TARGET :: buf2
  CHARACTER(LEN=3), TARGET :: buf3
  TYPE(C_PTR) :: f_ptr

  f_ptr = C_LOC(buf(1:1))      ! Used to fail
                               ! Error: CHARACTER argument 'buf' to 'c_loc'
                               ! at (1) must have a length of 1
  f_ptr = C_LOC(buf2(1)(1:1))  ! PASSES

  f_ptr = C_LOC(buf(n:n))

  f_ptr = C_LOC(buf3(3:))
END SUBROUTINE test