Silverfrost Forums

Welcome to our forums

Assumed size array of derived type + default initialization

7 Oct 2013 3:02 #13093

The compiler should generate an ERROR for the following code.

Since type foo_t contains some default initialization (a=1) it is not legal for an array of these to be associated with a dummy argument which is of assumed size and has intent out (assumed shape and intent out would be ok, as would assumed size when there is no default initialization).

Since the size of the dummy array is not known, the compiler cannot therefore carry out the required initialization when proc is called.

Regards David.

program anon

   implicit none
   
   type foo_t
      integer :: a = 1
      integer :: b
   end type foo_t

   type (foo_t), dimension(4) :: foo
   integer :: i
   
   foo%a = 0
   
   call proc(foo, 4)

   do i=1, 4
      print *, foo(i)%a, foo(i)%b, ' <-- should print 1, 2'
   end do

contains

   subroutine proc(foo, m)
      integer, intent(in) :: m
      type (foo_t), intent(out) :: foo(*)
      integer i
      do i=1, m
         foo(i)%b = 2
      end do
   end subroutine proc
   
end program anon
7 Oct 2013 4:52 #13095

Thanks. I have logged this for investigation.

11 Oct 2013 3:42 (Edited: 12 Oct 2013 10:11) #13136

Thanks Paul.

One thing to note is if you change foo(*) to foo(: ) to make it Standard conforming, the code prints 0, 2 on each line, which isn't correct.

This shows that the default initialisation caused by the use of Intent(Out) isn't being done. 😉

11 Oct 2013 5:19 #13137

Thanks. Conversion from smiley to Fortran is fortunately quite simple!

26 Mar 2014 2:50 #13892

This bug has now been fixed for the next release.

27 Mar 2014 7:39 #13900

Thanks Paul. I can't wait for the next release.

26 Apr 2014 10:45 #14005

With the new version, does the following code work?

It should print 444 but version 7 is printing 222, which is wrong.

Sorry to be a pain. But as there are 2 bugs in the above code I need to know which one was fixed, or if both were.

program anon 

    implicit none 
     
    type foo_t 
       integer :: a = 444 
    end type foo_t 

    type (foo_t) :: foo 
     
    foo%a = 222 
     
    call proc(foo) 

    print *, foo%a, ' <-- should print 444' 
 
 contains 

    subroutine proc(foo) 
       type (foo_t), intent(out) :: foo
       print *,'proc called'
    end subroutine proc 
     
 end program anon
26 Apr 2014 3:17 #14009

For the next release...

The assumed size array now produces an error. The assumed shape array now gives the right answer.

The latest example (not passing an array) is a new issue and it still fails. I will log this for investigation.

26 Apr 2014 4:51 #14010

OK Thanks.

9 Aug 2014 7:52 #14434

Quoted from PaulLaidler For the next release... The assumed size array now produces an error. The assumed shape array now gives the right answer.

Both working in 7.10.

Quoted from PaulLaidler

The latest example (not passing an array) is a new issue and it still fails. I will log this for investigation.

Confirmed.

Thanks Paul.

14 Jan 2015 1:34 #15297

The latter bug has now been fixed for the next release.

15 Jan 2015 7:34 #15302

Brilliant! Thanks a lot Paul.

Please login to reply.