+2009-10-07 Daniel Kraft <d@domob.eu>
+
+ PR fortran/41615
+ * resolve.c (resolve_contained_fntype): Clarify error message for
+ invalid assumed-length character result on module procedures.
+
2009-10-07 Janus Weil <janus@gcc.gnu.org>
* expr.c (gfc_check_pointer_assign): Do the correct type checking when
/* Fortran 95 Draft Standard, page 51, Section 5.1.1.5, on the Character
type, lists the only ways a character length value of * can be used:
dummy arguments of procedures, named constants, and function results
- in external functions. Internal function results are not on that list;
- ergo, not permitted. */
+ in external functions. Internal function results and results of module
+ procedures are not on this list, ergo, not permitted. */
if (sym->result->ts.type == BT_CHARACTER)
{
gfc_charlen *cl = sym->result->ts.u.cl;
if (!cl || !cl->length)
- gfc_error ("Character-valued internal function '%s' at %L must "
- "not be assumed length", sym->name, &sym->declared_at);
+ {
+ /* See if this is a module-procedure and adapt error message
+ accordingly. */
+ bool module_proc;
+ gcc_assert (ns->parent && ns->parent->proc_name);
+ module_proc = (ns->parent->proc_name->attr.flavor == FL_MODULE);
+
+ gfc_error ("Character-valued %s '%s' at %L must not be"
+ " assumed length",
+ module_proc ? _("module procedure")
+ : _("internal function"),
+ sym->name, &sym->declared_at);
+ }
}
}
+2009-10-07 Daniel Kraft <d@domob.eu>
+
+ PR fortran/41615
+ * gfortran.dg/assumed_charlen_function_6.f90: New test.
+
2009-10-07 Janus Weil <janus@gcc.gnu.org>
* gfortran.dg/same_type_as_2.f03: Modified (was illegal).
--- /dev/null
+! { dg-do compile }
+
+! PR fortran/41615
+! Output nicer error message for invalid assumed-len character function result
+! depending on what kind of contained procedure it is.
+
+module funcs
+ implicit none
+contains
+ function assumed_len(x) ! { dg-error "module procedure" }
+ character(*) assumed_len
+ integer, intent(in) :: x
+ end function assumed_len
+end module funcs
+
+module mod2
+ implicit none
+contains
+ subroutine mysub ()
+ contains
+ function assumed_len(x) ! { dg-error "internal function" }
+ character(*) assumed_len
+ integer, intent(in) :: x
+ end function assumed_len
+ end subroutine
+end module mod2
+
+program main
+ implicit none
+contains
+ function assumed_len(x) ! { dg-error "internal function" }
+ character(*) assumed_len
+ integer, intent(in) :: x
+ end function assumed_len
+end program main
+
+! { dg-final { cleanup-modules "funcs mod2" } }