-Wsurprising warning for overloaded intrinsic size

Hi all,

I am in a software package submission process, and when I undertake it I get the following warning that prevents me to complete it:

use numbers_utils
      |      1
Warning: Type specified for intrinsic function ‘size’ at (1) is ignored [-Wsurprising]

In particular, I have overloaded the intrinsic function “size” in the module “types”, that I import into “numbers_utils”. The definition of the overloaded interface follows:

interface size
  module procedure number__size
  module procedure graph__size
end interface size

...

pure function number__size (x) result(sz)
  implicit none
  type(number), intent(in) :: x
  integer :: sz
  sz  = 0
  if (is_allocated(x)) sz = product(x%shp)
end function number__size

pure function graph__size (x) result(sz)
  implicit none
  type(graph), intent(in) :: x
  integer :: sz
  sz = 0
  if (is_allocated(x)) sz = size(x%nodes)
end function graph__size

I am compiling with “gfortran” version 7.5.0 on Ubuntu 18.04, and am not able to reproduce the warning on my environment and not even a couple of VM that I have running on AWS. The submission process runs on a Debian server. As quick fix I will avoid the overloading which I think it is what is causing the problem. However I would be glad if someone could point me towards the actual cause of this warning, so as to correctly write the overloaded interface in the future.

Could you isolate a complete minimal working example?

I tried creating my own, but could not reproduce the error:

module test_size

  implicit none

  type graph
    real, allocatable :: nodes(:)
  end type

  interface size
    module procedure graph__size
  end interface

contains

  pure function graph__size (x) result(sz)
    implicit none
    type(graph), intent(in) :: x
    integer :: sz
    sz = 0
    if (allocated(x%nodes)) sz = size(x%nodes)
  end function graph__size

end module

module utils
  use test_size
end module

program main
  use utils
  implicit none
  type(graph) :: x

  allocate(x%nodes(10))
  print *, size(x)
end program

Hi @ivanpribec,

thanks a lot for thanking the time to try this out. Unfortunately I cannot reproduce the warning either. I tried locally, and on a couple of virtual machine in AWS without getting the warning.
I’ll try to isolate the example as you suggested.
Another detail is that type attributes in my case are pointers. Thus it should be

type graph
real, pointer :: nodes( : ) => null()
end type

Thanks again and I hope to get back with the isolated example asap!

Extending a existing generic (including an intrinsic one) is allowed as long as the new specific procedures are distinguishable from each other and from the existing specifics already in the generic. In particular, this process does not alter any of the existing specifics. So the Warning is, indeed, a “surprise”. I suspect it was a bug in gfortran in the past. Note that gfortran 7.5.0 is fairly old, and the problem might have been since fixed.

Hi @billlong,

that the conclusion I ended up with as well. Apologies to @ivanpribec it is quite time consuming for me to isolate a reproducible example from the large body of code I have. Further more I am quite skeptical on the possibility of reproducing the warning consistently. Thus I will take the answer of @billlong and close the issue. Thanks to you both for your help.

1 Like