llvm-project/flang/test/Semantics/array-constr-len.f90
Peter Klausler c6dd9f4278
[flang] Catch usage of : and * lengths in array c'tors (#128974)
The definition of an array constructor doesn't preclude the use of
[character(:)::] or [character(*)::] directly, but there is language
elsewhere in the standard that restricts their use to specific contexts,
neither of which include explicitly typed array constructors.

Fixes https://github.com/llvm/llvm-project/issues/128755.
2025-02-27 14:32:50 -08:00

19 lines
879 B
Fortran

! RUN: %python %S/test_errors.py %s %flang_fc1
! Confirm enforcement of F'2023 7.8 p5
subroutine subr(s,n)
character*(*) s
!ERROR: Array constructor implied DO loop has no iterations and indeterminate character length
print *, [(s(1:n),j=1,0)]
!ERROR: Array constructor implied DO loop has no iterations and indeterminate character length
print *, [(s(1:n),j=0,1,-1)]
!ERROR: Array constructor implied DO loop has no iterations and indeterminate character length
print *, [(s(1:j),j=1,0)]
print *, [(s(1:1),j=1,0)] ! ok
print *, [character(2)::(s(1:n),j=1,0)] ! ok
print *, [character(n)::(s(1:n),j=1,0)]
!ERROR: A length specifier of '*' or ':' may not appear in the type of an array constructor
print *, [ character(:) :: ]
!ERROR: A length specifier of '*' or ':' may not appear in the type of an array constructor
print *, [ character(*) :: ]
end