Skip to content

Commit

Permalink
[flang] More compile-time error checking for null implied DO loops in…
Browse files Browse the repository at this point in the history
… array constructors

An implied DO loop in an array constructor may not have a type (explicit
or otherwise) with a character length that depends on a value of an
implied DO index or a non-constant expression if the implied DO loop
executes no iterations.  When the iteration count can be known to be
zero at compilation time, catch the case of a non-constant length
expression correctly.

Differential Revision: https://reviews.llvm.org/D156753
  • Loading branch information
klausler committed Aug 1, 2023
1 parent bd077e9 commit 9c446da
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions flang/lib/Semantics/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1510,8 +1510,8 @@ class ArrayConstructorContext {
return std::nullopt;
}
bool NeedLength() const {
return !explicitType_ && type_ &&
type_->category() == TypeCategory::Character && !LengthIfGood();
return type_ && type_->category() == TypeCategory::Character &&
!LengthIfGood();
}
void Push(MaybeExpr &&);
void Add(const parser::AcValue::Triplet &);
Expand Down
3 changes: 2 additions & 1 deletion flang/test/Semantics/array-constr-len.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ subroutine subr(s,n)
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)] ! ok
!ERROR: Array constructor implied DO loop has no iterations and indeterminate character length
print *, [character(n)::(s(1:n),j=1,0)]
end

0 comments on commit 9c446da

Please sign in to comment.