From: Paul Thomas Date: Thu, 21 Jun 2018 22:38:55 +0000 (+0000) Subject: re PR fortran/49630 ([OOP] ICE on obsolescent deferred-length type bound character... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=77f72c95fafee28af8a7cf46b3304b7f46e8c732;p=gcc.git re PR fortran/49630 ([OOP] ICE on obsolescent deferred-length type bound character function) 2018-06-21 Paul Thomas PR fortran/49630 * resolve.c (resolve_contained_fntype): Change standard ref. from F95 to F2003: C418. Correct a spelling error in a comment. It is an error for an abstract interface to have an assumed character length result. * trans-expr.c (gfc_conv_procedure_call): Likewise change the standard reference. 2018-06-21 Paul Thomas PR fortran/49630 * gfortran.dg/assumed_charlen_function_7.f90: New test. From-SVN: r261868 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 852f36e8f7c..2e665d95a0f 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,13 @@ +2018-06-21 Paul Thomas + + PR fortran/49630 + * resolve.c (resolve_contained_fntype): Change standard ref. + from F95 to F2003: C418. Correct a spelling error in a comment. + It is an error for an abstract interface to have an assumed + character length result. + * trans-expr.c (gfc_conv_procedure_call): Likewise change the + standard reference. + 2018-06-21 Paul Thomas PR fortran/83118 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 1cc31652920..41040544ce5 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -601,9 +601,10 @@ resolve_contained_fntype (gfc_symbol *sym, gfc_namespace *ns) } } - /* Fortran 95 Draft Standard, page 51, Section 5.1.1.5, on the Character + /* Fortran 2003 Draft Standard, page 535, C418, on type-param-value type, lists the only ways a character length value of * can be used: - dummy arguments of procedures, named constants, and function results + dummy arguments of procedures, named constants, function results and + in allocate statements if the allocate_object is an assumed length dummy in external functions. Internal function results and results of module procedures are not on this list, ergo, not permitted. */ @@ -3103,7 +3104,7 @@ resolve_function (gfc_expr *expr) return false; } - /* If this ia a deferred TBP with an abstract interface (which may + /* If this is a deferred TBP with an abstract interface (which may of course be referenced), expr->value.function.esym will be set. */ if (sym && sym->attr.abstract && !expr->value.function.esym) { @@ -3112,6 +3113,17 @@ resolve_function (gfc_expr *expr) return false; } + /* If this is a deferred TBP with an abstract interface, its result + cannot be an assumed length character (F2003: C418). */ + if (sym && sym->attr.abstract && sym->attr.function + && sym->result->ts.u.cl->length == NULL) + { + gfc_error ("ABSTRACT INTERFACE %qs at %L must not have an assumed " + "character length result (F2003: C418)", sym->name, + &sym->declared_at); + return false; + } + /* Switch off assumed size checking and do this again for certain kinds of procedure, once the procedure itself is resolved. */ need_full_assumed_size++; diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index f369b1b1be9..dfc44f753e5 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -5941,7 +5941,7 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, { if (ts.u.cl->length == NULL) { - /* Assumed character length results are not allowed by 5.1.1.5 of the + /* Assumed character length results are not allowed by C418 of the 2003 standard and are trapped in resolve.c; except in the case of SPREAD (and other intrinsics?) and dummy functions. In the case of SPREAD, we take the character length of the first argument for the result. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 60d02cb4b9d..e1aeb10f154 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-06-21 Paul Thomas + + PR fortran/49630 + * gfortran.dg/assumed_charlen_function_7.f90: New test. + 2018-06-21 Paul Thomas PR fortran/83118 diff --git a/gcc/testsuite/gfortran.dg/assumed_charlen_function_7.f90 b/gcc/testsuite/gfortran.dg/assumed_charlen_function_7.f90 new file mode 100644 index 00000000000..b36bb872e7b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/assumed_charlen_function_7.f90 @@ -0,0 +1,34 @@ +! { dg-do compile } +! +! Test the fix for PR49630, comment #11. +! +! Contributed by Vittorio Zecca +! +module abc + implicit none + type,abstract::abc_abstract + contains + procedure(abc_interface),deferred::abc_function + end type abc_abstract + type,extends(abc_abstract)::abc_type + contains + procedure::abc_function + end type abc_type + abstract interface + function abc_interface(this) ! { dg-error "assumed character length result" } + import abc_abstract + class(abc_abstract),intent(in)::this + character(len=*)::abc_interface + end function abc_interface + end interface +contains + function abc_function(this) + class(abc_type),intent(in)::this + character(len=5)::abc_function + abc_function="hello" + end function abc_function + subroutine do_something(this) + class(abc_abstract),intent(in)::this + print *,this%abc_function() + end subroutine do_something +end module abc