[Bug fortran/104520] New: Unexpected behavior with STORAGE_SIZE intrinsic with a dummy argument that is unlimited polymorphic

fortranfan at outlook dot com gcc-bugzilla@gcc.gnu.org
Sun Feb 13 17:47:18 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104520

            Bug ID: 104520
           Summary: Unexpected behavior with STORAGE_SIZE intrinsic with a
                    dummy argument that is unlimited polymorphic
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fortranfan at outlook dot com
  Target Milestone: ---

Consider the following:

--- begin code ---
module m
   use, intrinsic :: iso_fortran_env, only : character_storage_size
contains
   subroutine sub( a )
      class(*), intent(in) :: a
      print *, "storage_size(s) = ", storage_size(a)
      select type ( a )
         type is ( character(len=*) )
            print *, "expected is ", len(a)*character_storage_size
      end select
   end subroutine 
end module
   use m 
   character(len=2) :: s
   call sub( s )
end
--- end code ---

And the program behavior using gfortran:
--- begin console output ---
C:\temp>gfortran -Wall y.f90 -o y.exe

C:\temp>y.exe
 storage_size(s) =            8
 expected is           16

C:\temp>
--- end output ---

On the other hand, consider the following:

--- begin code ---
   character(len=2) :: s
   print *, storage_size(s)
end
--- end code ---

The program behavior is

--- begin output ---
C:\temp>gfortran -Wall y.f90 -o y.exe

C:\temp>y.exe
          16

C:\temp>
--- end output ---

I failed to find anything in the Fortran standard that supports the above shown
program behavior.  Can the first case with the unlimited polymorphic dummy be
expected to the same as the second, meaning the storage size of the object get
determined as 16 bits?

Thank you,
Vipul Parekh


More information about the Gcc-bugs mailing list