This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Memory allocation failed because of parenthesis


Hi all, 


I want your thought concerning a parenthesis bug for the following code. The expression (a+b) works well, while ((a)+(b)) triggers a memory allocation issue.

And its works fine, if there is no allocatable components in the type. I guess it is a pointer pass to the subroutine that is wrong or a parser issue ? but I wasn't sure what title 

to give to the bug report in that case. I got this behavior with gfortran 4.9.2, and the code runs fine with intel compiler.



Thanks.
Pat.



module num
type :: my_integer
integer  :: value
double precision,dimension(:),allocatable :: x
contains
final :: destroy
procedure :: add => add_my_integer
procedure :: ass => ass_my_integer
generic, public :: assignment(=) => ass
generic, public :: operator(+) => add 
end type

contains
subroutine destroy(a)
type(my_integer) :: a
if(allocated(a%x)) deallocate(a%x)

end subroutine
function add_my_integer(a,b) result(r)
class(my_integer), intent(in) :: a
class(my_integer), intent(in) :: b
class(my_integer), allocatable :: r

print *,'called add_my_int'

select type (b)
type is (my_integer)
allocate(my_integer :: r)
select type (r)
type is (my_integer)
r%value = a%value+b%value
r%x = a%x+b%x
end select
end select
end function


subroutine ass_my_integer(a,b)
class(my_integer), intent(out) :: a
class(my_integer), intent(in) :: b

select type (b)
type is (my_integer)
allocate(a%x(size(b%x)))
a%value = b%value
a%x = b%x
end select
end subroutine

end module

program main
use num

class(my_integer), allocatable :: a, b, c
allocate(my_integer :: a)
allocate(my_integer :: b)
allocate(my_integer :: c)
a=my_integer(1,[1])
b=my_integer(2,[2])
c = (a+b)
write (*,*) c%value,c%x
c = ((a)+(b))
write (*,*) c%value,c%x
deallocate(a,b,c)
end program


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]