Bug 51948 - [4.6/4.7 Regression][OOP] Rejects valid: Function result value in MOVE_ALLOC, nested in SELECT TYPE
Summary: [4.6/4.7 Regression][OOP] Rejects valid: Function result value in MOVE_ALLOC,...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.6.3
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2012-01-22 17:31 UTC by Tobias Burnus
Modified: 2012-01-24 08:35 UTC (History)
1 user (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 2012-01-22 17:31:16 UTC
The following fails at move_alloc with bogus errors. The second example is based on the example from chapter09/burgers_factory_f2003/periodic_6th_order.F90 in the book http://www.cambridge.org/rouson

type t
end type t

contains
  function func(x)
    class(t), allocatable :: x(:), func(:)
    call move_alloc (x, func)
! FAILS: Error: the 'from' and 'to' arguments of 'move_alloc' intrinsic at (1) must have the same rank 0/1
  end function

  function func2(x)
    type(t), allocatable :: x
    class(t), allocatable :: func2
    call move_alloc (x, func)
! FAILS: Error: 'to' argument of 'move_alloc' intrinsic at (1) must be a variable
  end function
end
Comment 1 Tobias Burnus 2012-01-23 11:43:18 UTC
The second example is wrong - and it works after fixing it: s/func/func2/.

This program compiles with GCC 4.5 (and fails with 4.6/4.7) - thus, I marked the PR as regression.


Better example (still based on periodic_6th_order.F90). The SELECT TYPE is crucial, a simple ASSOCIATE or BLOCK won't do:

        call move_alloc (x, func)
                            1
Error: 'to' argument of 'move_alloc' intrinsic at (1) must be a variable


The program 


  type :: t
  end type t
contains
  function func(x, y)
    class(t) :: y                 ! Dummy variable
    type(t), allocatable :: func  ! Can also be CLASS
    type(t), allocatable :: x     ! Can also be CLASS

   ! call move_alloc (x, func) ! <<< Works

    select type (y)
      type is(t)
        call move_alloc (x, func) ! << Error (but no select variable involved)
    end select
  end function
end
Comment 2 Tobias Burnus 2012-01-23 20:38:27 UTC
Author: burnus
Date: Mon Jan 23 20:38:23 2012
New Revision: 183453

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183453
Log:
2012-01-23  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51948
        * check.c (variable_check): Fix checking for
        result variables and deeply nested BLOCKs.

2012-01-23  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51948
        * gfortran.dg/move_alloc_12.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/move_alloc_12.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/check.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 Tobias Burnus 2012-01-23 21:17:26 UTC
FIXED.
Comment 4 Tobias Burnus 2012-01-24 08:13:34 UTC
(In reply to comment #3)
> FIXED.

Well, the first part of comment 0 is not. I filled a new bug for for it: PR 51977.
Comment 5 Tobias Burnus 2012-01-24 08:35:15 UTC
Author: burnus
Date: Tue Jan 24 08:35:10 2012
New Revision: 183469

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183469
Log:
2012-01-24  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51948
        * check.c (variable_check): Fix checking for
        result variables and deeply nested BLOCKs.

2012-01-24  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51948
        * gfortran.dg/move_alloc_12.f90: New.


Added:
    branches/gcc-4_6-branch/gcc/testsuite/gfortran.dg/move_alloc_12.f90
Modified:
    branches/gcc-4_6-branch/gcc/fortran/ChangeLog
    branches/gcc-4_6-branch/gcc/fortran/check.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog