[Fortran] Fix to strict associate check (PR93427)
authorTobias Burnus <tobias@codesourcery.com>
Mon, 3 Feb 2020 09:00:07 +0000 (10:00 +0100)
committerTobias Burnus <tobias@codesourcery.com>
Mon, 3 Feb 2020 09:00:07 +0000 (10:00 +0100)
        PR fortran/93427
        * resolve.c (resolve_assoc_var): Remove too strict check.
        * gfortran.dg/associate_51.f90: Update test case.

        PR fortran/93427
        * gfortran.dg/associate_52.f90: New.

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/associate_51.f90
gcc/testsuite/gfortran.dg/associate_52.f90 [new file with mode: 0644]

index 2b188e513b77c9f990ff5f77c96a715c214d7952..570cacbd8471422b3ed8c33fc648865d85100ecd 100644 (file)
@@ -1,3 +1,9 @@
+2020-02-03  Tobias Burnus  <tobias@codesourcery.com>
+
+       PR fortran/93427
+       * resolve.c (resolve_assoc_var): Remove too strict check.
+       * gfortran.dg/associate_51.f90: Update test case.
+
 2020-02-01  Jakub Jelinek  <jakub@redhat.com>
 
        PR fortran/92305
index e840aec62f234864f5a34ccd203dee04744954fa..8f5267fde052b2c0ba167e40a458bf192e8dc180 100644 (file)
@@ -8846,8 +8846,7 @@ resolve_assoc_var (gfc_symbol* sym, bool resolve_target)
 
       if (tsym->attr.subroutine
          || tsym->attr.external
-         || (tsym->attr.function
-             && (tsym->result != tsym || tsym->attr.recursive)))
+         || (tsym->attr.function && tsym->result != tsym))
        {
          gfc_error ("Associating entity %qs at %L is a procedure name",
                     tsym->name, &target->where);
index 86b9edcad56813b77a19f7d2c0ab68badc3d95d3..8f116971229b8684326a11e9c8e52a55d6b5510a 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-03  Tobias Burnus  <tobias@codesourcery.com>
+
+       PR fortran/93427
+       * gfortran.dg/associate_52.f90: New.
+
 2020-02-03  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/93533
index 7b3edc44990f664feb9bcc5549ec04ae65c8b4df..b6ab1414b02ed33742d896a74fbdb21f8f2ff0f4 100644 (file)
@@ -14,7 +14,14 @@ end
 recursive function f2()
   associate (y1 => f2()) ! { dg-error "Invalid association target" }
   end associate          ! { dg-error "Expecting END FUNCTION statement" }
-  associate (y2 => f2)   ! { dg-error "is a procedure name" }
+end
+
+recursive function f3()
+  associate (y1 => f3)
+    print *, y1()  ! { dg-error "Expected array subscript" }
+  end associate
+  associate (y2 => f3) ! { dg-error "Associate-name 'y2' at \\(1\\) is used as array" }
+    print *, y2(1)
   end associate
 end
 
diff --git a/gcc/testsuite/gfortran.dg/associate_52.f90 b/gcc/testsuite/gfortran.dg/associate_52.f90
new file mode 100644 (file)
index 0000000..c24ec4b
--- /dev/null
@@ -0,0 +1,24 @@
+! { dg-do compile }
+!
+! PR fortran/93427
+!
+! Contributed by Andrew Benson
+!
+module a
+
+type :: t
+end type t
+
+contains
+
+recursive function b()
+  class(t), pointer :: b
+  type(t) :: c
+  allocate(t :: b)
+  select type (b)
+  type is (t)
+     b=c
+  end select
+end function b
+
+end module a