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

             Bug #: 51380
           Summary: ASSIGNMENT(=): Reject ALLOCATABLE/POINTER dummy
                    argument
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid, diagnostic
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: bur...@gcc.gnu.org


The following program is invalid as the call to the assignment function should
act as if the "from" argument is enclosed in parentheses. That directly implies
that the actual argument cannot be allocatable or a pointer.

For the topic and the standard, cf.
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/13ac0c0e52339468

Note: Strictly speaking, only the call to the function is invalid while the
declaration is valid (but may not be used).


>From the standard (F2003, found by Richard Maine):
  "A defined assignment is treated as a reference to the subroutine,
   with the left-hand side as the first argument and the right-hand-side
   enclosed in parentheses as the second argument." (12.3.2.1.2, paragraph 2)


Possibilities:
* Error for the usage
* Error for the declaration (even if valid, it may not be used)
* Warning for the declaration, error for using it

The following program is compiled without any error/(default) warning in
gfortran.

While the IBM compiler prints the error (as stated in c.l.f):
  (S) Dummy argument sets of procedure or binding assign_set_i4_2_pv must
  not be specified with the ALLOCATABLE attribute. assign_set_i4_2_pv
  will not be included in the ASSIGNMENT(=) generic interface.


module m
  type t1
    integer :: i
  end type t1
  type t2
    real :: r
  end type t2
  interface assignment(=)
    module procedure assign1
    module procedure assign2
  end interface
contains
  subroutine assign1 (a, b)
    type(t1), intent(out) :: a
    type(t1), intent(in), ALLOCATABLE :: b ! valid but questionable
    a%i = b%i
  end subroutine assign1
  subroutine assign2 (a, b)
    type(t2), intent(out) :: a
    type(t2), intent(in), POINTER :: b ! valid but questionable
    a%r = b%r
  end subroutine assign2
end module m

use m
type(t1), allocatable :: x1
type(t2), pointer :: x2
allocate(x1, x2)
x1 = x1   ! << Invalid, equivalent to: call assign1(x1, (x1))
          !             and (x1) is not allocatable
x1 = (x1) ! << Similarly invalid, but with explicit (.)
x2 = x2   ! << Invalid, equivalent to: call assign2(x1, (x1))
          !             and (x2) is not a pointer
x2 = (x2) ! << Similarly invalid, but with explicit (.)
end

Reply via email to