llvm-project/flang/test/Semantics/zero_len_char_array.f90
TMJ fcec9ced47
[flang] Do not error on constant nonzero UB in substring of ZLA (#174511)
A substring reference where the lower bound is higher than the upper
bound is defined in 9.4.1 to be zero-length.

Thus, a reference to a substring of a CHARACTER*(0) string such as

    string(foo():2)

cannot be a compile-time error since we do not know the return value of
foo().

We also should not error if the lbound > ubound at compile time.
2026-01-08 13:28:48 -05:00

38 lines
973 B
Fortran

! RUN: %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck --allow-empty %s
! CHECK-NOT: error:
! Test that zero-length character substrings with lbound>ubounds indices
! do not produce spurious errors when the character array is zero length.
program flang_t7052
implicit none
character*(*), parameter :: param_char = ""
character*(0) :: zero_len_char
if ( param_char(init(5):init(3)) > zero_len_char(1:-2) ) then
print *,"Test failed"
endif
if ( param_char(init(5):init(3)) > zero_len_char(10:2) ) then
print *,"Test failed"
endif
if ( param_char(init(5):init(3)) > zero_len_char(init(10):2) ) then
print *,"Test failed"
endif
if ( param_char(init(5):init(3)) > zero_len_char(init(10):-2) ) then
print *,"Test failed"
endif
if ( param_char(init(5):init(3)) > zero_len_char(2:init(10)) ) then
print *,"Test failed"
endif
contains
integer function init(i)
integer, intent(in) :: i
init=i
end
end program