Skip to content

Commit 9c446da

Browse files
committed
[flang] More compile-time error checking for null implied DO loops in 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
1 parent bd077e9 commit 9c446da

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

flang/lib/Semantics/expression.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,8 +1510,8 @@ class ArrayConstructorContext {
15101510
return std::nullopt;
15111511
}
15121512
bool NeedLength() const {
1513-
return !explicitType_ && type_ &&
1514-
type_->category() == TypeCategory::Character && !LengthIfGood();
1513+
return type_ && type_->category() == TypeCategory::Character &&
1514+
!LengthIfGood();
15151515
}
15161516
void Push(MaybeExpr &&);
15171517
void Add(const parser::AcValue::Triplet &);

flang/test/Semantics/array-constr-len.f90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ subroutine subr(s,n)
1010
print *, [(s(1:j),j=1,0)]
1111
print *, [(s(1:1),j=1,0)] ! ok
1212
print *, [character(2)::(s(1:n),j=1,0)] ! ok
13-
print *, [character(n)::(s(1:n),j=1,0)] ! ok
13+
!ERROR: Array constructor implied DO loop has no iterations and indeterminate character length
14+
print *, [character(n)::(s(1:n),j=1,0)]
1415
end

0 commit comments

Comments
 (0)