Skip to content

Commit 0d55927

Browse files
authored
[flang] Catch deferred type parameters in ALLOCATE(type-spec::) (#139334)
The type-spec in ALLOCATE may not have any deferred type parameters. Fixes #138979.
1 parent d90bbf1 commit 0d55927

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

flang/lib/Semantics/check-allocate.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,19 @@ static std::optional<AllocateCheckerInfo> CheckAllocateOptions(
116116
// C937
117117
if (auto it{FindCoarrayUltimateComponent(*derived)}) {
118118
context
119-
.Say("Type-spec in ALLOCATE must not specify a type with a coarray"
120-
" ultimate component"_err_en_US)
119+
.Say(
120+
"Type-spec in ALLOCATE must not specify a type with a coarray ultimate component"_err_en_US)
121121
.Attach(it->name(),
122122
"Type '%s' has coarray ultimate component '%s' declared here"_en_US,
123123
info.typeSpec->AsFortran(), it.BuildResultDesignatorName());
124124
}
125125
}
126+
if (auto dyType{evaluate::DynamicType::From(*info.typeSpec)}) {
127+
if (dyType->HasDeferredTypeParameter()) {
128+
context.Say(
129+
"Type-spec in ALLOCATE must not have a deferred type parameter"_err_en_US);
130+
}
131+
}
126132
}
127133

128134
const parser::Expr *parserSourceExpr{nullptr};

flang/test/Semantics/allocate01.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ subroutine bar()
6262
real, pointer, save :: okp3
6363
real, allocatable, save :: oka3, okac4[:,:]
6464
real, allocatable :: okacd5(:, :)[:]
65+
character(:), allocatable :: chvar
6566

6667
!ERROR: Name in ALLOCATE statement must be a variable name
6768
allocate(foo)
@@ -102,6 +103,8 @@ subroutine bar()
102103
allocate(edc9%nok)
103104
!ERROR: Entity in ALLOCATE statement must have the ALLOCATABLE or POINTER attribute
104105
allocate(edc10)
106+
!ERROR: Type-spec in ALLOCATE must not have a deferred type parameter
107+
allocate(character(:) :: chvar)
105108

106109
! No errors expected below:
107110
allocate(a_var)
@@ -117,4 +120,5 @@ subroutine bar()
117120
allocate(edc9%ok(4))
118121
allocate(edc10%ok)
119122
allocate(rp)
123+
allocate(character(123) :: chvar)
120124
end subroutine

0 commit comments

Comments
 (0)