Bug 41585 - [OOP] Reject CLASS(T) as component of "TYPE :: T"
Summary: [OOP] Reject CLASS(T) as component of "TYPE :: T"
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2009-10-05 13:22 UTC by Tobias Burnus
Modified: 2009-10-09 22:39 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-10-07 21:50:03


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2009-10-05 13:22:12 UTC
type t
  integer :: i
  class(t), allocatable :: foo
end type t

In Fortran 2003 this is invalid to have CLASS(T) in the same TYPE as the one being defined. I think Fortran 2008 allows this, but as currently, deallocating also does not work, I would simply reject it.


C438 (R440) If the POINTER attribute is not specified for a component, the declaration-type-spec in the component-def-stmt shall be CLASS(*) or shall specify an intrinsic type or a previously defined derived type.

C439 (R440) If the POINTER attribute is specified for a component, the declaration-type-spec in the component-def-stmt shall be CLASS(*) or shall specify an intrinsic type or any accessible derived type including the type being defined.
Comment 1 Tobias Burnus 2009-10-05 13:27:18 UTC
See also PR 41586.
Comment 2 janus 2009-10-07 21:50:03 UTC
This can be fixed by:

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c  (Revision 152525)
+++ gcc/fortran/decl.c  (Arbeitskopie)
@@ -1465,7 +1465,7 @@ build_struct (const char *name, gfc_charlen *cl, g

   /* If the current symbol is of the same derived type that we're
      constructing, it must have the pointer attribute.  */
-  if (current_ts.type == BT_DERIVED
+  if ((current_ts.type == BT_DERIVED || current_ts.type == BT_CLASS)
       && current_ts.u.derived == gfc_current_block ()
       && current_attr.pointer == 0)
     {
Comment 3 janus 2009-10-09 22:35:29 UTC
Subject: Bug 41585

Author: janus
Date: Fri Oct  9 22:35:11 2009
New Revision: 152608

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=152608
Log:
2009-10-09  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/41585
	* decl.c (build_struct): Bugfix for CLASS components.


2009-10-09  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/41585
	* gfortran.dg/class_2.f03: Extended test case.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/class_2.f03

Comment 4 janus 2009-10-09 22:39:21 UTC
Fixed with r152608. Closing.