Skip to content

Commit c6dd9f4

Browse files
authored
[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 #128755.
1 parent 78acf7b commit c6dd9f4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

flang/lib/Semantics/expression.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ static std::optional<DynamicTypeWithLength> AnalyzeTypeSpec(
7878
const semantics::CharacterTypeSpec &cts{
7979
typeSpec->characterTypeSpec()};
8080
const semantics::ParamValue &len{cts.length()};
81-
// N.B. CHARACTER(LEN=*) is allowed in type-specs in ALLOCATE() &
82-
// type guards, but not in array constructors.
81+
if (len.isAssumed() || len.isDeferred()) {
82+
context.messages().Say(
83+
"A length specifier of '*' or ':' may not appear in the type of an array constructor"_err_en_US);
84+
}
8385
DynamicTypeWithLength type{DynamicType{kind, len}};
8486
if (auto lenExpr{type.LEN()}) {
8587
type.length = Fold(context,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ subroutine subr(s,n)
1111
print *, [(s(1:1),j=1,0)] ! ok
1212
print *, [character(2)::(s(1:n),j=1,0)] ! ok
1313
print *, [character(n)::(s(1:n),j=1,0)]
14+
!ERROR: A length specifier of '*' or ':' may not appear in the type of an array constructor
15+
print *, [ character(:) :: ]
16+
!ERROR: A length specifier of '*' or ':' may not appear in the type of an array constructor
17+
print *, [ character(*) :: ]
1418
end

0 commit comments

Comments
 (0)