re PR fortran/43207 ([OOP] invalid (pointer) assignment to and from abstract non...
authorJanus Weil <janus@gcc.gnu.org>
Sat, 3 Dec 2016 18:48:48 +0000 (19:48 +0100)
committerJanus Weil <janus@gcc.gnu.org>
Sat, 3 Dec 2016 18:48:48 +0000 (19:48 +0100)
2016-12-03  Janus Weil  <janus@gcc.gnu.org>

PR fortran/43207
* primary.c (gfc_match_varspec): Reject nonpolymorphic references to
abstract types.

2016-12-03  Janus Weil  <janus@gcc.gnu.org>

PR fortran/43207
* gfortran.dg/abstract_type_9.f90: New test case.

From-SVN: r243224

gcc/fortran/ChangeLog
gcc/fortran/primary.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/abstract_type_9.f90 [new file with mode: 0644]

index eaae6961dfe8144f7fcee497873e259d1f5a1e98..3489bc4a14e6319178c96c6544549007fc2ca19c 100644 (file)
@@ -1,3 +1,9 @@
+2016-12-03  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/43207
+       * primary.c (gfc_match_varspec): Reject nonpolymorphic references to
+       abstract types.
+
 2016-12-03  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/42188
index 2cdc9a4a23ca103007d46f26c6e57391e18424ea..f13b0f02f15f896a8b47cccbd2a800539de4e28f 100644 (file)
@@ -2222,7 +2222,15 @@ check_substring:
        }
     }
 
-  /* F2008, C727.  */
+  /* F08:C611.  */
+  if (primary->ts.type == BT_DERIVED && primary->ref
+      && primary->ts.u.derived && primary->ts.u.derived->attr.abstract)
+    {
+      gfc_error ("Nonpolymorphic reference to abstract type at %C");
+      return MATCH_ERROR;
+    }
+
+  /* F08:C727.  */
   if (primary->expr_type == EXPR_PPC && gfc_is_coindexed (primary))
     {
       gfc_error ("Coindexed procedure-pointer component at %C");
index 0d95973ef8a98e9db82b5f67e6866290e497f702..84fc6fa83bc65ddae44c1b2076fc0ec4f4ed742a 100644 (file)
@@ -1,3 +1,8 @@
+2016-12-03  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/43207
+       * gfortran.dg/abstract_type_9.f90: New test case.
+
 2016-12-03  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/42188
diff --git a/gcc/testsuite/gfortran.dg/abstract_type_9.f90 b/gcc/testsuite/gfortran.dg/abstract_type_9.f90
new file mode 100644 (file)
index 0000000..77d48ba
--- /dev/null
@@ -0,0 +1,34 @@
+! { dg-do compile }
+!
+! PR 43207: [OOP] invalid (pointer) assignment to and from abstract non-polymorphic expressions
+!
+! Contributed by Tobias Burnus <burnus@gcc.gnu.org>
+
+  implicit none
+  type, abstract :: parent
+    integer :: i
+  end type
+  type, extends(parent) :: child
+    class(parent), pointer :: comp
+  end type
+
+  type(child), target :: c1
+  class(child), allocatable :: c2
+  class(parent), pointer :: cp
+
+  c1%parent = c1%parent  ! { dg-error "Nonpolymorphic reference to abstract type" }
+  c2%parent = c1%parent  ! { dg-error "Nonpolymorphic reference to abstract type" }
+
+  cp => c1%comp
+  cp => c1%parent        ! { dg-error "Nonpolymorphic reference to abstract type" }
+
+  call sub(c1%comp)
+  call sub(c1%parent)    ! { dg-error "Nonpolymorphic reference to abstract type" }
+
+contains
+
+  subroutine sub(arg)
+    class(parent) :: arg
+  end subroutine
+
+end