Patchwork [Fortran] PR58652 - accept CLASS(*) as argument to CLASS(*)

login
register
mail settings
Submitter Tobias Burnus
Date Oct. 15, 2013, 10:38 p.m.
Message ID <525DC3FA.5080804@net-b.de>
Download mbox | patch
Permalink /patch/283797/
State New
Headers show

Comments

Tobias Burnus - Oct. 15, 2013, 10:38 p.m.
As the test case (see also PR) showed, gfortran was rejecting:

      subroutine list_move_alloc(self,item)
        class(list_node),intent(inout) :: self
        class(*),intent(inout),allocatable :: item
...
      class(*), allocatable :: expr
...
        call ast%move_alloc(expr)

with the bogus message:

         call ast%move_alloc(expr)
                             1
Error: Actual argument to 'item' at (1) must have the same declared type


The attached patch now also accepts passing CLASS(*) to CLASS(*).

Built and currently regtesting on x86-64-gnu-linux (when successful:)
OK for the trunk?

Tobias
Paul Richard Thomas - Oct. 16, 2013, 8:54 a.m.
Dear Tobias,

Your patch is fine for trunk.

Thanks

Paul

On 16 October 2013 00:38, Tobias Burnus <burnus@net-b.de> wrote:
> As the test case (see also PR) showed, gfortran was rejecting:
>
>      subroutine list_move_alloc(self,item)
>        class(list_node),intent(inout) :: self
>        class(*),intent(inout),allocatable :: item
> ...
>      class(*), allocatable :: expr
> ...
>        call ast%move_alloc(expr)
>
> with the bogus message:
>
>         call ast%move_alloc(expr)
>                             1
> Error: Actual argument to 'item' at (1) must have the same declared type
>
>
> The attached patch now also accepts passing CLASS(*) to CLASS(*).
>
> Built and currently regtesting on x86-64-gnu-linux (when successful:)
> OK for the trunk?
>
> Tobias

Patch

2013-10-16  Tobias Burnus  <burnus@net-b.de>

	PR fortran/58652
	* interface.c (compare_parameter): Accept passing CLASS(*)
	to CLASS(*).

2013-10-16  Tobias Burnus  <burnus@net-b.de>

	PR fortran/58652
	* gfortran.dg/unlimited_polymorphic_12.f90: New.

diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index b878644..b3ddf5f 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -1990,8 +1990,9 @@  compare_parameter (gfc_symbol *formal, gfc_expr *actual,
       if (!gfc_expr_attr (actual).class_ok)
 	return 0;
 
-      if (!gfc_compare_derived_types (CLASS_DATA (actual)->ts.u.derived,
-				      CLASS_DATA (formal)->ts.u.derived))
+      if ((!UNLIMITED_POLY (formal) || !UNLIMITED_POLY(actual))
+	  && !gfc_compare_derived_types (CLASS_DATA (actual)->ts.u.derived,
+					 CLASS_DATA (formal)->ts.u.derived))
 	{
 	  if (where)
 	    gfc_error ("Actual argument to '%s' at %L must have the same "
diff --git a/gcc/testsuite/gfortran.dg/unlimited_polymorphic_12.f90 b/gcc/testsuite/gfortran.dg/unlimited_polymorphic_12.f90
new file mode 100644
index 0000000..c583c6b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/unlimited_polymorphic_12.f90
@@ -0,0 +1,44 @@ 
+! { dg-do compile }
+!
+! PR fortran/58652
+!
+! Contributed by Vladimir Fuka
+!
+! The passing of a CLASS(*) to a CLASS(*) was reject before
+!
+module gen_lists
+  type list_node
+    class(*),allocatable :: item
+    contains
+      procedure :: move_alloc => list_move_alloc
+  end type
+
+  contains
+
+    subroutine list_move_alloc(self,item)
+      class(list_node),intent(inout) :: self
+      class(*),intent(inout),allocatable :: item
+
+      call move_alloc(item, self%item)
+    end subroutine
+end module
+
+module lists
+  use gen_lists, only: node => list_node
+end module lists
+
+
+module sexp
+  use lists
+contains
+ subroutine parse(ast)
+    class(*), allocatable, intent(out) :: ast
+    class(*), allocatable :: expr
+    integer :: ierr
+    allocate(node::ast)
+    select type (ast)
+      type is (node)
+        call ast%move_alloc(expr)
+    end select
+  end subroutine
+end module