Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Bug with STORAGE_SIZE?

Jacob_Williams
New Contributor II
220 Views

I'm seeing something odd here. If I use STORAGE_SIZE on a CLASS(*) variable to initialize a character string using REPEAT, the result is different if I put the size in a temporary variable, or in the actual routine call.  See below:

program test

  implicit none
  
  call bug(1)

contains

  subroutine bug(k)
  
   use iso_fortran_env, only: CHARACTER_STORAGE_SIZE
   
   implicit none
   
   class(*),intent(in) :: k
   
   character(len=:),allocatable :: s1,s2
   integer :: n
   
   n = storage_size(k)/CHARACTER_STORAGE_SIZE	!works if size is put in temp variable
   s1 = repeat(' ', n)
   write(*,*) 'len(s1)=',len(s1)	!prints 4
   	
   s2 = repeat(' ', storage_size(k)/CHARACTER_STORAGE_SIZE)	!doesn't work!
   write(*,*) 'len(s2)=',len(s2)	!prints 0
  
  end subroutine bug

end program test

 

0 Kudos
1 Reply
Kevin_D_Intel
Employee
220 Views

Thank you for reporting this and for the nice reproducer. It does appear the usage producing the incorrect results should work. I reported this to Development.

(Internal tracking id: DPD200378821)

0 Kudos
Reply