[flang-commits] [flang] 7991078 - [flang] Allow empty SEQUENCE types (#66252)

via flang-commits flang-commits at lists.llvm.org
Mon Sep 18 12:11:40 PDT 2023


Author: Peter Klausler
Date: 2023-09-18T12:11:35-07:00
New Revision: 79910786324eca8d5a0535f6361b507c3d38f61f

URL: https://github.com/llvm/llvm-project/commit/79910786324eca8d5a0535f6361b507c3d38f61f
DIFF: https://github.com/llvm/llvm-project/commit/79910786324eca8d5a0535f6361b507c3d38f61f.diff

LOG: [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.

Added: 
    

Modified: 
    flang/docs/Extensions.md
    flang/lib/Semantics/resolve-names.cpp
    flang/test/Semantics/resolve31.f90

Removed: 
    


################################################################################
diff  --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index 49e78a10fa6bcdb..4d0b2c7319818a7 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -428,6 +428,9 @@ end
 * Since Fortran 90, INCLUDE lines have been allowed to have
   a numeric kind parameter prefix on the file name.  No other
   Fortran compiler supports them that I can find.
+* A `SEQUENCE` derived type is required (F'2023 C745) to have
+  at least one component.  No compiler enforces this constraint;
+  this compiler emits a warning.
 
 ## Behavior in cases where the standard is ambiguous or indefinite
 

diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 8e2b33ab2078b94..47ecaa1b82e53ed 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5226,9 +5226,10 @@ bool DeclarationVisitor::Pre(const parser::DerivedTypeDef &x) {
   Walk(componentDefs);
   if (derivedTypeInfo_.sequence) {
     details.set_sequence(true);
-    if (componentDefs.empty()) { // C740
+    if (componentDefs.empty()) {
+      // F'2023 C745 - not enforced by any compiler
       Say(stmt.source,
-          "A sequence type must have at least one component"_err_en_US);
+          "A sequence type should have at least one component"_warn_en_US);
     }
     if (!details.paramNames().empty()) { // C740
       Say(stmt.source,

diff  --git a/flang/test/Semantics/resolve31.f90 b/flang/test/Semantics/resolve31.f90
index 0c604c0ee9734b9..6bf8e877a515668 100644
--- a/flang/test/Semantics/resolve31.f90
+++ b/flang/test/Semantics/resolve31.f90
@@ -68,7 +68,7 @@ module m4
   !ERROR: A sequence type may not have a CONTAINS statement
   contains
   end type
-  !ERROR: A sequence type must have at least one component
+  !WARNING: A sequence type should have at least one component
   type :: emptyType
     sequence
   end type emptyType


        


More information about the flang-commits mailing list