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

            Bug ID: 93330
           Summary: CHARACTER: Wrong kind=4 resolution +   missing
                    string-length mismatch actual/dummy diagnostic
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: accepts-invalid, diagnostic, rejects-valid
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: tkoenig at gcc dot gnu.org
  Target Milestone: ---

Created attachment 47682
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47682&action=edit
Test case

Found when looking at the posted patch for PR 85781.

There are three issues:
* 4_"abc"(2:2) is wrongly converted to a kind-1 character → rejects-valid
* Passing a zero-length string to a nonzero-length dummy argument gives no
  warning (or error). [Note: passing a len > 0 string does] → diagnostic
* Passing a too-long kind-4 character string should give an error/warning
  but it does not. → diagnostic

One can argue whether a warning or an error is better; the standard has "shell"
but it is not a constraint.

 * * *

Related: I wonder whether some -W option should also warn when passing a too
long string. While valid, it can be sometimes surprising if one passes some
argument – and it then gets truncated, e.g.

call foo('abc')
contains
  subroutine foo(x)
   character(len=2) :: x
   print *, x
end
end

 * * *

Fortran 2018 has in 15.5.2.4:

"The length type parameter values of a present actual argument shall agree with
the corresponding ones of the dummy argument that are not assumed, except for
the case of the character length parameter of an actual argument of type
character with default kind or C character kind (18.2.2) associated with a
dummy argument that is not assumed-shape or assumed-rank.

"If a present scalar dummy argument is of type character with default kind or C
character kind, the length len of the dummy argument shall be less than or
equal to the length of the actual argument. The dummy argument becomes
associated with the leftmost len characters of the actual argument. If a
present array dummy argument is of type character with default kind or C
character kind and is not assumed-shape or assumed-rank, it becomes associated
with the leftmost characters of the actual argument element sequence
(15.5.2.11)."

Reply via email to