public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/45516]  New: [F08] allocatable compontents of recursive type
@ 2010-09-03  9:57 janus at gcc dot gnu dot org
  2010-09-03  9:59 ` [Bug fortran/45516] " janus at gcc dot gnu dot org
  2010-09-03 12:12 ` burnus at gcc dot gnu dot org
  0 siblings, 2 replies; 8+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-09-03  9:57 UTC (permalink / raw)
  To: gcc-bugs

John Reid, The new features of Fortran 2008, chapter 5.3:

A recursive type is permitted to be based on allocatable components. Here is a
simple example of a type that holds a stack:

type entry
  real :: value
  integer :: index
  type(entry), allocatable :: next
end type entry

[...]

For this gfortran currently gives:

  type(entry), allocatable :: next
                                  1
Error: Component at (1) must have the POINTER attribute


-- 
           Summary: [F08] allocatable compontents of recursive type
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: janus at gcc dot gnu dot org
OtherBugsDependingO 39627
             nThis:


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45516


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/45516] [F08] allocatable compontents of recursive type
  2010-09-03  9:57 [Bug fortran/45516] New: [F08] allocatable compontents of recursive type janus at gcc dot gnu dot org
@ 2010-09-03  9:59 ` janus at gcc dot gnu dot org
  2010-09-03 12:12 ` burnus at gcc dot gnu dot org
  1 sibling, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-09-03  9:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from janus at gcc dot gnu dot org  2010-09-03 09:59 -------
Here is a patch to accept the type declaration in comment #0:

Index: decl.c
===================================================================
--- decl.c      (revision 163798)
+++ decl.c      (working copy)
@@ -1494,11 +1494,11 @@ build_struct (const char *name, gfc_charlen *cl, g
   gfc_component *c;
   gfc_try t = SUCCESS;

-  /* F03:C438/C439. If the current symbol is of the same derived type that
we're
-     constructing, it must have the pointer attribute.  */
+  /* F08:C440. If the current symbol is of the same derived type that we're
+     constructing, it must be POINTER or ALLOCATABLE.  */
   if ((current_ts.type == BT_DERIVED || current_ts.type == BT_CLASS)
       && current_ts.u.derived == gfc_current_block ()
-      && current_attr.pointer == 0)
+      && !current_attr.pointer && !current_attr.allocatable)
     {
       gfc_error ("Component at %C must have the POINTER attribute");
       return FAILURE;


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45516


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/45516] [F08] allocatable compontents of recursive type
  2010-09-03  9:57 [Bug fortran/45516] New: [F08] allocatable compontents of recursive type janus at gcc dot gnu dot org
  2010-09-03  9:59 ` [Bug fortran/45516] " janus at gcc dot gnu dot org
@ 2010-09-03 12:12 ` burnus at gcc dot gnu dot org
  1 sibling, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-09-03 12:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from burnus at gcc dot gnu dot org  2010-09-03 12:12 -------
(In reply to comment #1)
> Here is a patch to accept the type declaration in comment #0:

Well, you at least need to use gfc_notify_std(GFC_STD_F2008, ... And one should
make sure that the allocation/clean up works as expected.

 * * *

As follow up to the initial implementation, one should implement at some point
the following, which does not do a deep copy but simply appends the old data.
(Example from the mentioned article.)

type entry
  real :: value
  integer :: index
  type(entry), allocatable :: next
end type entry

type (entry), allocatable :: top
top = entry ( new_value, new_index, top )

(The last line assume reallocate on assignment; I think it already works for
derived types with structure constructor; I know that it does not yet work for
intrinsic types - not does it work on other assignment than structure
constructors.)

The classical way to append a new item is the following, which should avoid a
deep copy (check!):

  type (entry), allocatable :: top, temp
  temp = entry ( new_value, new_index, temp )
  call move_alloc(top,temp%next)
  call move_alloc(temp,top)


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |domob at gcc dot gnu dot
                   |                            |org, burnus at gcc dot gnu
                   |                            |dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45516


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/45516] [F08] allocatable compontents of recursive type
       [not found] <bug-45516-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2012-08-29  9:18 ` burnus at gcc dot gnu.org
@ 2020-10-21 12:39 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-10-21 12:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=45516

--- Comment #12 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tobias Burnus <burnus@gcc.gnu.org>:

https://gcc.gnu.org/g:310fe80babe04ccb7d2e15c8fca7dc98180701a8

commit r11-4186-g310fe80babe04ccb7d2e15c8fca7dc98180701a8
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Wed Oct 21 14:38:44 2020 +0200

    Fortran: class.c - update vtable comment

    gcc/fortran/
            PR fortran/45516
            * class.c: Add _deallocate to the vtable documentation
            comment.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/45516] [F08] allocatable compontents of recursive type
       [not found] <bug-45516-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2011-02-06 13:02 ` janus at gcc dot gnu.org
@ 2012-08-29  9:18 ` burnus at gcc dot gnu.org
  2020-10-21 12:39 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-08-29  9:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45516

--- Comment #6 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-08-29 09:18:01 UTC ---
Test case by Wolfgang Kilian in the "Function questions?" thread:
https://groups.google.com/d/msg/comp.lang.fortran/r4PVbtaBnFM/hufoSWKHDBIJ

When handling the deallocation, we need to ensure that also the FINAL wrapper
properly handles it.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/45516] [F08] allocatable compontents of recursive type
       [not found] <bug-45516-4@http.gcc.gnu.org/bugzilla/>
  2011-02-03 22:03 ` janus at gcc dot gnu.org
  2011-02-06 12:36 ` janus at gcc dot gnu.org
@ 2011-02-06 13:02 ` janus at gcc dot gnu.org
  2012-08-29  9:18 ` burnus at gcc dot gnu.org
  2020-10-21 12:39 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu.org @ 2011-02-06 13:02 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45516

--- Comment #5 from janus at gcc dot gnu.org 2011-02-06 12:36:40 UTC ---
With the patch in comment #4, we currently get an ICE on the following test
case:


type entry1
  real :: value
  type(entry1), allocatable :: next
end type entry1

type(entry1), allocatable :: x

allocate(x)

end


The problem is that we run into an infinite loop when trying to auto-deallocate
x and the whole chain of its components, cf. gfc_deallocate_scalar_with_status,
gfc_deallocate_alloc_comp and structure_alloc_comps.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/45516] [F08] allocatable compontents of recursive type
       [not found] <bug-45516-4@http.gcc.gnu.org/bugzilla/>
  2011-02-03 22:03 ` janus at gcc dot gnu.org
@ 2011-02-06 12:36 ` janus at gcc dot gnu.org
  2011-02-06 13:02 ` janus at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu.org @ 2011-02-06 12:36 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45516

--- Comment #4 from janus at gcc dot gnu.org 2011-02-06 12:28:42 UTC ---
We also need to adjust gfc_get_derived_type, to avoid running into an infinite
loop. Updated patch:


Index: gcc/testsuite/gfortran.dg/class_2.f03
===================================================================
--- gcc/testsuite/gfortran.dg/class_2.f03    (revision 169853)
+++ gcc/testsuite/gfortran.dg/class_2.f03    (working copy)
@@ -36,7 +36,7 @@ end interface

 type t6
   integer :: i
-  class(t6), allocatable :: foo  ! { dg-error "must have the POINTER
attribute" }
+  class(t6) :: foo  ! { dg-error "must be POINTER or ALLOCATABLE" }
 end type t6


Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c    (revision 169853)
+++ gcc/fortran/decl.c    (working copy)
@@ -1515,14 +1515,20 @@ build_struct (const char *name, gfc_charlen *cl, g
   gfc_component *c;
   gfc_try t = SUCCESS;

-  /* F03:C438/C439. If the current symbol is of the same derived type that
we're
-     constructing, it must have the pointer attribute.  */
+  /* F03:C438/C439, F08:C440. If the current symbol is of the same derived
type
+     that we're constructing, it must be POINTER or ALLOCATABLE.  */
   if ((current_ts.type == BT_DERIVED || current_ts.type == BT_CLASS)
       && current_ts.u.derived == gfc_current_block ()
       && current_attr.pointer == 0)
     {
-      gfc_error ("Component at %C must have the POINTER attribute");
-      return FAILURE;
+      if (gfc_notify_std (GFC_STD_F2008, "Component at %C must have the "
+              "POINTER attribute") == FAILURE)
+    return FAILURE;
+      else if (current_attr.allocatable == 0)
+    {
+      gfc_error ("Component at %C must be POINTER or ALLOCATABLE");
+      return FAILURE;
+    }
     }

   if (gfc_current_block ()->attr.pointer && (*as)->rank != 0)
Index: gcc/fortran/trans-types.c
===================================================================
--- gcc/fortran/trans-types.c    (revision 169853)
+++ gcc/fortran/trans-types.c    (working copy)
@@ -2096,14 +2096,14 @@ gfc_get_derived_type (gfc_symbol * derived)
   /* Go through the derived type components, building them as
      necessary. The reason for doing this now is that it is
      possible to recurse back to this derived type through a
-     pointer component (PR24092). If this happens, the fields
+     pointer or allocatable component. If this happens, the fields
      will be built and so we can return the type.  */
   for (c = derived->components; c; c = c->next)
     {
       if (c->ts.type != BT_DERIVED && c->ts.type != BT_CLASS)
     continue;

-      if ((!c->attr.pointer && !c->attr.proc_pointer)
+      if ((!c->attr.pointer && !c->attr.proc_pointer && !c->attr.allocatable)
       || c->ts.u.derived->backend_decl == NULL)
     c->ts.u.derived->backend_decl = gfc_get_derived_type (c->ts.u.derived);


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/45516] [F08] allocatable compontents of recursive type
       [not found] <bug-45516-4@http.gcc.gnu.org/bugzilla/>
@ 2011-02-03 22:03 ` janus at gcc dot gnu.org
  2011-02-06 12:36 ` janus at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu.org @ 2011-02-03 22:03 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45516

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.02.03 22:03:06
     Ever Confirmed|0                           |1

--- Comment #3 from janus at gcc dot gnu.org 2011-02-03 22:03:06 UTC ---
(In reply to comment #2)
> (In reply to comment #1)
> > Here is a patch to accept the type declaration in comment #0:
> 
> Well, you at least need to use gfc_notify_std(GFC_STD_F2008, ...


This variant keeps the old error message for -std=f2003:

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c  (revision 169519)
+++ gcc/fortran/decl.c  (working copy)
@@ -1515,14 +1515,20 @@ build_struct (const char *name, gfc_charlen *cl, g
   gfc_component *c;
   gfc_try t = SUCCESS;

-  /* F03:C438/C439. If the current symbol is of the same derived type that
we're
-     constructing, it must have the pointer attribute.  */
+  /* F03:C438/C439, F08:C440. If the current symbol is of the same derived
type
+     that we're constructing, it must be POINTER or ALLOCATABLE.  */
   if ((current_ts.type == BT_DERIVED || current_ts.type == BT_CLASS)
       && current_ts.u.derived == gfc_current_block ()
       && current_attr.pointer == 0)
     {
-      gfc_error ("Component at %C must have the POINTER attribute");
-      return FAILURE;
+      if (gfc_notify_std (GFC_STD_F2008, "Component at %C must have the "
+                         "POINTER attribute") == FAILURE)
+       return FAILURE;
+      else if (current_attr.allocatable == 0)
+       {
+         gfc_error ("Component at %C must be POINTER or ALLOCATABLE");
+         return FAILURE;
+       }
     }

   if (gfc_current_block ()->attr.pointer && (*as)->rank != 0)


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-10-21 12:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-03  9:57 [Bug fortran/45516] New: [F08] allocatable compontents of recursive type janus at gcc dot gnu dot org
2010-09-03  9:59 ` [Bug fortran/45516] " janus at gcc dot gnu dot org
2010-09-03 12:12 ` burnus at gcc dot gnu dot org
     [not found] <bug-45516-4@http.gcc.gnu.org/bugzilla/>
2011-02-03 22:03 ` janus at gcc dot gnu.org
2011-02-06 12:36 ` janus at gcc dot gnu.org
2011-02-06 13:02 ` janus at gcc dot gnu.org
2012-08-29  9:18 ` burnus at gcc dot gnu.org
2020-10-21 12:39 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).