[flang-commits] [PATCH] D117154: [flang] Any type can appear in a structure constructor for an unlimited polymorphic allocatable component

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Jan 13 10:38:03 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGbb59b38e87f8: [flang] Any type can appear in a structure constructor for an unlimited… (authored by klausler).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117154/new/

https://reviews.llvm.org/D117154

Files:
  flang/lib/Semantics/expression.cpp
  flang/test/Semantics/structconst01.f90


Index: flang/test/Semantics/structconst01.f90
===================================================================
--- flang/test/Semantics/structconst01.f90
+++ flang/test/Semantics/structconst01.f90
@@ -66,5 +66,18 @@
       k=2,m=3))
     !ERROR: ABSTRACT derived type 'abstract' may not be used in a structure constructor
     call abstractarg(abstract(0)(n=1))
+    !This case is ok
   end subroutine errors
+  subroutine polycomponent
+    type :: poly
+      class(*), allocatable :: p
+    end type poly
+    type(poly) :: x
+    ! These cases are not errors
+    x = poly(1)
+    x = poly('hello')
+    x = poly(type1(1)(123))
+    !ERROR: Value in structure constructor is incompatible with  component 'p' of type CLASS(*)
+    x = poly(z'feedface')
+  end subroutine
 end module module1
Index: flang/lib/Semantics/expression.cpp
===================================================================
--- flang/lib/Semantics/expression.cpp
+++ flang/lib/Semantics/expression.cpp
@@ -1739,7 +1739,10 @@
         } else if (IsAllocatable(*symbol) && IsBareNullPointer(&*value)) {
           // NULL() with no arguments allowed by 7.5.10 para 6 for ALLOCATABLE
         } else if (auto symType{DynamicType::From(symbol)}) {
-          if (valueType) {
+          if (IsAllocatable(*symbol) && symType->IsUnlimitedPolymorphic() &&
+              valueType) {
+            // ok
+          } else if (valueType) {
             AttachDeclaration(
                 Say(expr.source,
                     "Value in structure constructor of type %s is "


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117154.399723.patch
Type: text/x-patch
Size: 1550 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220113/00ba3ff8/attachment.bin>


More information about the flang-commits mailing list