Bug 48887 - [4.7 Regression][OOP] SELECT TYPE: Associate name shall not be a pointer/allocatable
Summary: [4.7 Regression][OOP] SELECT TYPE: Associate name shall not be a pointer/all...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.7.0
Assignee: Daniel Kraft
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2011-05-05 13:09 UTC by Tobias Burnus
Modified: 2011-12-03 18:34 UTC (History)
2 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2011-05-05 13:09:43 UTC
From F2008, 16.5.1.6 Construct association:

"If the selector is allocatable, it shall be allocated; the associate name is associated with the data object and does not have the ALLOCATABLE attribute.

"If the selector has the POINTER attribute, it shall be associated; the associate name is associated with the target of the pointer and does not have the POINTER attribute."


However, gfortran accepts the following, ifort and NAG don't.

It works if the associate name is explicitly given using "associate-name => selector"; however, it does not change the POINTER/ALLOCATABLE issue as: "The associate name of a SELECT TYPE construct is the associate-name if specified; otherwise it is the name that constitutes the selector."


type t
end type t
class(t), allocatable :: alloc
class(t), pointer     :: ptr

select type(alloc)
type is (t)
  allocate(alloc) ! INVALID: "alloc" is not allocatable
end select

select type(ptr)
type is (t)
  nullify(ptr) ! INVALID: "ptr" is not a pointer
end select

end

For an longer example, see 
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/88b65a2c9024e95f
Comment 1 Daniel Kraft 2011-05-06 17:10:47 UTC
Taking this.
Comment 2 Daniel Kraft 2011-05-27 10:59:01 UTC
In match.c:select_type_set_tmp we have around line 4536:

  if (select_type_stack->selector->ts.type == BT_CLASS &&
      CLASS_DATA (select_type_stack->selector)->attr.allocatable)
    gfc_add_allocatable (&tmp->n.sym->attr, NULL);
  else
    gfc_add_pointer (&tmp->n.sym->attr, NULL);

Simply removing those gives ICEs in some SELECT TYPE test cases.

In resolve.c:resolve_select_type around line 7937 (the resolve_assoc_var call), st->n.sym shows the respective attributes which lead to the problem later on.

Note that it we simply use ASSOCIATE, the attributes are not set (as is expected and should be).
Comment 3 janus 2011-06-16 14:32:38 UTC
Note: Apparenty "select_type_23.f03" in the testsuite is invalid due to this PR (cf. PR 48699).
Comment 4 Tobias Burnus 2011-12-02 16:21:50 UTC
At least for the following test case there is a regression. While the "must be ALLOCATABLE" is printed correctly three times with GCC 4.6, with GCC 4.7 I only get the error for ASSOCIATE (as expected, cf. comment 2) and not for SELECT TYPE.

type t
end type t
class(t), allocatable :: x

! Expected: An error, but none is printed:
select type(x)
  type is(t)
    print *, allocated (x) ! { dg-error "must be ALLOCATABLE" }
end select

! Expected: An error, but none is printed:
select type(y=>x)
  type is(t)
    print *, allocated (y)  ! { dg-error "must be ALLOCATABLE" }
end select

! Here, the error is printed:
associate (y=>x)
  print *, allocated (y)  ! { dg-error "must be ALLOCATABLE" }
end associate
end
Comment 5 Tobias Burnus 2011-12-03 18:30:40 UTC
Author: burnus
Date: Sat Dec  3 18:30:36 2011
New Revision: 181975

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181975
Log:
2011-12-03  Tobias Burnus  <burnus@net-b.de>

        PR fortran/48887
        * match.c (select_type_set_tmp): Don't set allocatable/pointer
        attribute.
        * class.c (gfc_build_class_symbol): Handle
        attr.select_type_temporary.

2011-12-03  Tobias Burnus  <burnus@net-b.de>

        PR fortran/48887
        * gfortran.dg/select_type_24.f90: New.
        * gfortran.dg/select_type_23.f03: Add dg-error.
        * gfortran.dg/class_45a.f03: Add missing TARGET attribute.


Added:
    trunk/gcc/testsuite/gfortran.dg/select_type_24.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/class.c
    trunk/gcc/fortran/match.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/class_45a.f03
    trunk/gcc/testsuite/gfortran.dg/select_type_23.f03
Comment 6 Tobias Burnus 2011-12-03 18:34:13 UTC
FIXED on the 4.7 trunk.