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

--- Comment #3 from kargl at gcc dot gnu.org ---
(In reply to anlauf from comment #1)
> (In reply to Ben Brewer from comment #0)
> Workaround: either use -std=legacy or fix the above argument declaration to:
> 
>       CHARACTER C1D001(*)*8,CVD001*8

While the workaround will work, it does so because it disables
-fallow-argument-mismatch.  But, that feature emitting a bogus
error/warning.

Note the following all compile and execute.  TKR is satisfied
as I discussion in comment #2.

! Compiles and executes
program foo1
   character(len=10) a
   a = '1234567890'
   call sub1(a)
end
subroutine sub1(s)
   character(len=8) s
   print *, '>' // s // '<'
end

! Compiles and executes
program foo2
   character(len=10) a(5)
   a = '1234567890'
   call sub2(a)
end
subroutine sub2(s)
    character(len=8) s(2)
   print *, '>' // s(1) // '<'
end

! Compiles and executes
program foo3
   character(len=10) a(5)
   a = '1234567890'
   call sub3(a(2)(2:4))
end
subroutine sub3(s)
    character(len=8) s(2)
   print *, '>' // s(1) // '<'
end

But,

% gfcx -o z a.f90 && ./z
a.f90:40:13:

   40 |    call sub4(a(2)(2:4))
      |             1
Error: Actual argument contains too few elements for dummy
argument 's' (39/80) at (1)

! Whoops
program foo4
   character(len=10) a(5)
   a = '1234567890'
   call sub4(a(2)(2:4))
end
subroutine sub4(s)
    character(len=8) s(10)    ! <-- only difference from foo3
   print *, '>' // s(1) // '<'
end

The give away that something is amiss is the (39/80) part of
the error message.  80 = 8*10, i.e., total number of characters.
I cannot quite get 39.  39 = 50 - 11, but 11 does not match up
with the substring length of a(2)(2:4).

Now, looking at interface.cc starting at line 3354, we have


          if (a->expr->ts.type == BT_CHARACTER && !f->sym->as && where)
            {
              gfc_warning (0, "Character length of actual argument shorter "
                           "than of dummy argument %qs (%lu/%lu) at %L",
                           f->sym->name, actual_size, formal_size,
                           &a->expr->where);
              goto skip_size_check;
            }
          else if (where)
            {
              /* Emit a warning for -std=legacy and an error otherwise. */
              if (gfc_option.warn_std == 0)
                gfc_warning (0, "Actual argument contains too few "
                             "elements for dummy argument %qs (%lu/%lu) "
                             "at %L", f->sym->name, actual_size,
                             formal_size, &a->expr->where);
              else
                gfc_error_now ("Actual argument contains too few "
                               "elements for dummy argument %qs (%lu/%lu) "
                               "at %L", f->sym->name, actual_size,
                               formal_size, &a->expr->where);
            }

clearly we want the first branch about character length, so
`where` == NULL

Reply via email to