goto failure;
}
+ /* F2003:C626 (R623) A type-param-value in a type-spec shall be an asterisk
+ if and only if each allocate-object is a dummy argument for which the
+ corresponding type parameter is assumed. */
+ if (code->ext.alloc.ts.type == BT_CHARACTER
+ && code->ext.alloc.ts.u.cl->length != NULL
+ && e->ts.type == BT_CHARACTER && !e->ts.deferred
+ && e->ts.u.cl->length == NULL
+ && e->symtree->n.sym->attr.dummy)
+ {
+ gfc_error ("The type parameter in ALLOCATE statement with type-spec "
+ "shall be an asterisk as allocate object %qs at %L is a "
+ "dummy argument with assumed type parameter",
+ sym->name, &e->where);
+ goto failure;
+ }
+
/* Check F08:C632. */
if (code->ext.alloc.ts.type == BT_CHARACTER && !e->ts.deferred
&& !UNLIMITED_POLY (e))
--- /dev/null
+! { dg-do compile }
+! PR fortran/119338 - check F2003:C626
+
+module m
+ implicit none
+contains
+ subroutine sub (s, c)
+ character(len=*), allocatable, intent(out) :: s(:)
+ character(len=*), allocatable, intent(out) :: c
+ allocate(s(5)) ! OK
+ allocate(c) ! OK
+ allocate(character(len=*) :: s(5)) ! OK
+ allocate(character(len=*) :: c) ! OK
+ allocate(character(len=10) :: s(5)) ! { dg-error "shall be an asterisk" }
+ allocate(character(len=10) :: c) ! { dg-error "shall be an asterisk" }
+ end subroutine sub
+end module m
character(*), allocatable, intent(out) :: str
! Note: Star ^ should have been a colon (:)
- allocate (character(n)::str)
+! allocate (character(n)::str) ! original invalid version from pr82367
+ allocate (character(*)::str) ! corrected (see F2003:C626 and pr119338)
end subroutine