Skip to content

Commit 7991078

Browse files
authored
[flang] Allow empty SEQUENCE types (#66252)
The Fortran standards require (F'2023 C745) that a derived type with the SEQUENCE attribute have at least one component. No Fortran compiler actually enforces this constraint. Accept this usage with a warning.
1 parent 4573577 commit 7991078

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

flang/docs/Extensions.md

+3
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ end
428428
* Since Fortran 90, INCLUDE lines have been allowed to have
429429
a numeric kind parameter prefix on the file name. No other
430430
Fortran compiler supports them that I can find.
431+
* A `SEQUENCE` derived type is required (F'2023 C745) to have
432+
at least one component. No compiler enforces this constraint;
433+
this compiler emits a warning.
431434

432435
## Behavior in cases where the standard is ambiguous or indefinite
433436

flang/lib/Semantics/resolve-names.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -5226,9 +5226,10 @@ bool DeclarationVisitor::Pre(const parser::DerivedTypeDef &x) {
52265226
Walk(componentDefs);
52275227
if (derivedTypeInfo_.sequence) {
52285228
details.set_sequence(true);
5229-
if (componentDefs.empty()) { // C740
5229+
if (componentDefs.empty()) {
5230+
// F'2023 C745 - not enforced by any compiler
52305231
Say(stmt.source,
5231-
"A sequence type must have at least one component"_err_en_US);
5232+
"A sequence type should have at least one component"_warn_en_US);
52325233
}
52335234
if (!details.paramNames().empty()) { // C740
52345235
Say(stmt.source,

flang/test/Semantics/resolve31.f90

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module m4
6868
!ERROR: A sequence type may not have a CONTAINS statement
6969
contains
7070
end type
71-
!ERROR: A sequence type must have at least one component
71+
!WARNING: A sequence type should have at least one component
7272
type :: emptyType
7373
sequence
7474
end type emptyType

0 commit comments

Comments
 (0)