Bug 41582 - [OOP] Allocation of abstract types requires a type spec or a SOURCE
Summary: [OOP] Allocation of abstract types requires a type spec or a SOURCE
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2009-10-05 12:53 UTC by Tobias Burnus
Modified: 2016-11-16 12:08 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Patch allocate(class) w/o source=/type-spec; plus PR 41581 interim fix (completely untested) (644 bytes, patch)
2009-10-08 15:39 UTC, Tobias Burnus
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2009-10-05 12:53:03 UTC
type, abstract :: t
  end type t
  class(t), allocatable :: a
  allocate(a)
is wrong. For the allocate one has to use either
  allocate(derived-type :: a)
or
  allocate(a, source=some_type_or_class)

One needs to reject this at compile time.

 * * *

Another interesting issue is:

type, abstract :: t
end type t
class(t), allocatable :: a,b
allocate(a, source=b)
end

That is invalid as "b" is not allocated, i.e. it does not have a dynamic type. A check could/should be implemented at the same time as PR 41581.
Comment 1 Tobias Burnus 2009-10-08 15:39:17 UTC
Created attachment 18753 [details]
Patch allocate(class) w/o source=/type-spec; plus PR 41581 interim fix (completely untested)

Patch also changes the warning of allocate(...,source=class) into an error, cf. PR 41581. Patch is untested - not even by compiling.
Comment 2 Tobias Burnus 2009-10-09 20:34:49 UTC
Subject: Bug 41582

Author: burnus
Date: Fri Oct  9 20:34:35 2009
New Revision: 152601

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=152601
Log:
2009-10-09  Tobias Burnus  <burnus@net-b.de>

        PR fortran/41582
        * decl.c (encapsulate_class_symbol): Save attr.abstract.
        * resolve.c (resolve_allocate_expr): Reject class allocate
        without typespec or source=.
        * trans-stmt.c (gfc_trans_allocate): Change gfc_warning
        into gfc_error for "not yet implemented".

2009-10-09  Tobias Burnus  <burnus@net-b.de>

        PR fortran/41582
        * gfortran.dg/class_allocate_1.f03: Modify code such that
        it compiles with the gfc_warning->gfc_error change.
        * gfortran.dg/class_allocate_1.f03: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/class_allocate_2.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/trans-stmt.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/class_allocate_1.f03

Comment 3 Tobias Burnus 2009-10-09 20:42:42 UTC
Close as FIXED.