[Bug fortran/104164] New: Bogus warning issued by -Wsurprising

juergen.reuter at desy dot de gcc-bugzilla@gcc.gnu.org
Fri Jan 21 13:37:29 GMT 2022


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

            Bug ID: 104164
           Summary: Bogus warning issued by -Wsurprising
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: juergen.reuter at desy dot de
  Target Milestone: ---

The code below (using iso_varying_string and a child module in the same module
gives a bogus warning from -Wsurprsing
reproducendum.f90:110:6:

  110 |   use diagnostics
      |      1
Warning: Type specified for intrinsic function ‘len’ at (1) is ignored
[-Wsurprising]
Depending on the order of the two use statements in the final module
(os_interface), this warning appears either once or twice! 


Reproducer:

module iso_varying_string

  implicit none
  integer, parameter, private :: GET_BUFFER_LEN = 1

  type, public :: varying_string
     private
     character(LEN=1), dimension(:), allocatable :: chars
  end type varying_string

  interface assignment(=)
     module procedure op_assign_CH_VS
     module procedure op_assign_VS_CH
  end interface assignment(=)

  interface char
     module procedure char_auto
     module procedure char_fixed
  end interface char

  interface len
     module procedure len_
  end interface len

  interface trim
     module procedure trim_
  end interface trim

  public :: assignment(=)
  public :: char
  public :: len
  public :: trim

  private :: op_assign_CH_VS
  private :: op_assign_VS_CH
  private :: char_auto
  private :: char_fixed
  private :: len_
  private :: trim_

contains

  elemental function len_ (string) result (length)
    type(varying_string), intent(in) :: string
    integer                          :: length
    if(ALLOCATED(string%chars)) then
       length = SIZE(string%chars)
    else
       length = 0
    endif
  end function len_

  elemental subroutine op_assign_CH_VS (var, exp)
    character(LEN=*), intent(out)    :: var
    type(varying_string), intent(in) :: exp
  end subroutine op_assign_CH_VS

  elemental subroutine op_assign_VS_CH (var, exp)
    type(varying_string), intent(out) :: var
    character(LEN=*), intent(in)      :: exp
  end subroutine op_assign_VS_CH

  pure function char_auto (string) result (char_string)
    type(varying_string), intent(in) :: string
    character(LEN=len(string))       :: char_string
    integer                          :: i_char
    forall(i_char = 1:len(string))
       char_string(i_char:i_char) = string%chars(i_char)
    end forall
  end function char_auto

  pure function char_fixed (string, length) result (char_string)
    type(varying_string), intent(in) :: string
    integer, intent(in)              :: length
    character(LEN=length)            :: char_string
    char_string = char(string)
  end function char_fixed

  elemental function trim_ (string) result (trim_string)
    type(varying_string), intent(in) :: string
    type(varying_string)             :: trim_string
    trim_string = TRIM(char(string))
  end function trim_

end module iso_varying_string


module diagnostics
  use iso_varying_string, string_t => varying_string
  implicit none
  private
  public :: int2char
  public :: int2fixed

contains
  pure function int2fixed (i) result (c)
    integer, intent(in) :: i
    character(200) :: c
  end function int2fixed
  pure function int2char (i) result (c)
    integer, intent(in) :: i
    character(len (trim (int2fixed (i)))) :: c
  end function int2char

end module diagnostics


module os_interface
  use iso_varying_string, string_t => varying_string
  use diagnostics
end module os_interface


More information about the Gcc-bugs mailing list