Bug 43696 - [OOP] Bogus error: Passed-object dummy argument must not be POINTER
Summary: [OOP] Bogus error: Passed-object dummy argument must not be POINTER
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2010-04-08 21:05 UTC by janus
Modified: 2010-05-05 08:13 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-05-03 20:03:44


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description janus 2010-04-08 21:05:59 UTC
Consider the following (supposedly valid) code:


MODULE error_stack_module
  implicit none
  
  type,abstract::serializable_class
   contains
     procedure(ser_DTV_RF),deferred::read_formatted
  end type serializable_class

  abstract interface
     subroutine ser_DTV_RF(dtv,unit,iotype,v_list,iostat,iomsg)
       import serializable_class
       CLASS(serializable_class),INTENT(INOUT) :: dtv
       INTEGER, INTENT(IN) :: unit
       CHARACTER (LEN=*), INTENT(IN) :: iotype
       INTEGER, INTENT(IN) :: v_list(:)
       INTEGER, INTENT(OUT) :: iostat
       CHARACTER (LEN=*), INTENT(INOUT) :: iomsg
     end subroutine ser_DTV_RF
  end interface

  type,extends(serializable_class)::error_type
     class(error_type),pointer::next=>null()
   contains
     procedure::read_formatted=>error_read_formatted
  end type error_type
  
contains

  recursive subroutine error_read_formatted(dtv,unit,iotype,v_list,iostat,iomsg)
    CLASS(error_type),INTENT(INOUT) :: dtv
    INTEGER, INTENT(IN) :: unit
    CHARACTER (LEN=*), INTENT(IN) :: iotype
    INTEGER, INTENT(IN) :: v_list(:)
    INTEGER, INTENT(OUT) :: iostat
    CHARACTER (LEN=*), INTENT(INOUT) :: iomsg
    character(8),allocatable::type
    character(8),allocatable::next
    call basic_read_string(unit,type)
    call basic_read_string(unit,next)
    if(next=="NEXT")then
       allocate(dtv%next)
       call dtv%next%read_formatted(unit,iotype,v_list,iostat,iomsg)
    end if
  end subroutine error_read_formatted

 end MODULE error_stack_module


With current trunk, compilation results in:


error_stack.f03:25.14:

     procedure::read_formatted=>error_read_formatted
              1
Error: Passed-object dummy argument of 'error_read_formatted' at (1) must not be POINTER
error_stack.f03:22.46:

  type,extends(serializable_class)::error_type
                                              1
Error: Derived-type 'error_type' declared at (1) must be ABSTRACT because 'read_formatted' is DEFERRED and not overridden
f951: internal compiler error: in resolve_class_esym, at fortran/resolve.c:5255


The first error message is apparently bogus, the second one seems to be a consequence of the first one. The ICE may be a separate issue.
Comment 1 janus 2010-04-08 21:11:02 UTC
Forgot to mention: This one was reported by Hans-Werner Boschmann (thanks!).
Comment 2 Dominique d'Humieres 2010-04-08 21:24:36 UTC
Note there is no ICE with fortran-dev.
Comment 3 Tobias Burnus 2010-04-09 08:42:34 UTC
(In reply to comment #0)
> Error: Passed-object dummy argument of 'error_read_formatted' at (1) must not
> be POINTER

The error message itself is OK as the constraint is (F2008 FDIS):

"C456 The passed-object dummy argument shall be a scalar, nonpointer, nonallocatable dummy data object with the same declared type as the type being defined; all of its length type parameters shall be assumed; it shall be polymorphic (4.3.1.3) if and only if the type being defined is extensible (4.5.7). It shall not have the VALUE attribute."

However, if one looks at the object:
  type,extends(serializable_class)::error_type
    [...]
  contains
    procedure :: read_formatted => error_read_formatted
[...]
  recursive subroutine error_read_formatted(dtv,unit,iotype,v_list,iostat,iomsg)
    CLASS(error_type),INTENT(INOUT) :: dtv

The constraint seems to be fulfilled:
 "dtv" is a scalar, nonpointer, nonallocatable dummy. It does not have any length type parameters and it is not VALUE. And its type (well, class) is "error_type" as the type in which is it used - and CLASS is allows because "error_type" is extensible.

The check itself in resolve.c also looks OK:
  me_arg->ts.u.derived->components->attr.class_pointer
but it seems as if either the first component is checked (which would be is wrong) or as if the wrong type is used. One has:

  type,extends(serializable_class)::error_type
     class(error_type),pointer::next=>null()

The component is polymorphic and of the same type and it is a POINTER; I assume that is the cause of the trouble.
Comment 4 Hans-Werner Boschmann 2010-04-09 15:22:37 UTC
I've tried to isolate the error message from the ICE. The smallest code is a_module for the error and b_module for the ICE. a_module is valid f2003 code but b_module is not, it contains a pointer of undefined class. I guess that this case occurs when error_stack_module is compiled: error_type will not be defined in consequence of the "must not be POINTER" error but will be used as class later.

module a_module
  implicit none
  type::a_type
     class(a_type),pointer::a_component
   contains
     procedure::proc=>a_proc
  end type a_type
contains
  subroutine a_proc(this)
    class(a_type)::this
  end subroutine a_proc
end module a_module

!!$ > gfortran -c a.f03
!!$ a.f03:6.14:
!!$
!!$      procedure::proc=>a_proc
!!$               1
!!$ Error: Passed-object dummy argument of 'a_proc' at (1) must not be POINTER

module b_module
  implicit none
  type::b_type
     class(not_yet_defined_type_type),pointer::b_component
  end type b_type
end module b_module

!!$ > gfortran -c b.f03
!!$ f951: internal compiler error: in find_typebound_proc_uop, at fortran/symbol.c:4863
!!$ Please submit a full bug report,
!!$ with preprocessed source if appropriate.
!!$ See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 5 janus 2010-04-12 09:50:44 UTC
(In reply to comment #4)
> I've tried to isolate the error message from the ICE. The smallest code is
> a_module for the error and b_module for the ICE. 

Thanks. However, ...


> !!$ f951: internal compiler error: in find_typebound_proc_uop, at
> fortran/symbol.c:4863

this ICE seems to be different from the one in comment #0.
Comment 6 janus 2010-05-03 20:03:43 UTC
Mine. I think fixing comment #0 is as easy as the following two-liner:


Index: gcc/fortran/symbol.c
===================================================================
--- gcc/fortran/symbol.c	(revision 158970)
+++ gcc/fortran/symbol.c	(working copy)
@@ -4720,6 +4720,8 @@ gfc_build_class_symbol (gfc_typespec *ts, symbol_a
     sprintf (name, ".class.%s.%d.a", ts->u.derived->name, (*as)->rank);
   else if ((*as) && (*as)->rank)
     sprintf (name, ".class.%s.%d", ts->u.derived->name, (*as)->rank);
+  else if (attr->pointer)
+    sprintf (name, ".class.%s.p", ts->u.derived->name);
   else if (attr->allocatable)
     sprintf (name, ".class.%s.a", ts->u.derived->name);
   else


Apparently this doesn't even induce any testsuite regressions. However, the ICE in comment #4 will need some additional care.

Btw, the ICE in comment #0 is gone already since fortran-dev has been merged to trunk.
Comment 7 janus 2010-05-05 07:45:02 UTC
Subject: Bug 43696

Author: janus
Date: Wed May  5 07:44:33 2010
New Revision: 159056

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159056
Log:
2010-05-05  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/43696
	* resolve.c (resolve_fl_derived): Some fixes for class variables.
	* symbol.c (gfc_build_class_symbol): Add separate class container for
	class pointers.


2010-05-05  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/43696
	* gfortran.dg/class_17.f03: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/class_17.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/testsuite/ChangeLog

Comment 8 janus 2010-05-05 08:13:24 UTC
Fixed with r159056. Closing.