Skip to content

[flang] Catch deferred type parameters in ALLOCATE(type-spec::) #139334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions flang/lib/Semantics/check-allocate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,19 @@ static std::optional<AllocateCheckerInfo> CheckAllocateOptions(
// C937
if (auto it{FindCoarrayUltimateComponent(*derived)}) {
context
.Say("Type-spec in ALLOCATE must not specify a type with a coarray"
" ultimate component"_err_en_US)
.Say(
"Type-spec in ALLOCATE must not specify a type with a coarray ultimate component"_err_en_US)
.Attach(it->name(),
"Type '%s' has coarray ultimate component '%s' declared here"_en_US,
info.typeSpec->AsFortran(), it.BuildResultDesignatorName());
}
}
if (auto dyType{evaluate::DynamicType::From(*info.typeSpec)}) {
if (dyType->HasDeferredTypeParameter()) {
context.Say(
"Type-spec in ALLOCATE must not have a deferred type parameter"_err_en_US);
}
}
}

const parser::Expr *parserSourceExpr{nullptr};
Expand Down
4 changes: 4 additions & 0 deletions flang/test/Semantics/allocate01.f90
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ subroutine bar()
real, pointer, save :: okp3
real, allocatable, save :: oka3, okac4[:,:]
real, allocatable :: okacd5(:, :)[:]
character(:), allocatable :: chvar

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

! No errors expected below:
allocate(a_var)
Expand All @@ -117,4 +120,5 @@ subroutine bar()
allocate(edc9%ok(4))
allocate(edc10%ok)
allocate(rp)
allocate(character(123) :: chvar)
end subroutine