The code: module ice type::ice_type contains procedure::ice_func end type ice_type contains pure integer function ice_func(this) class(ice_type),intent(in)::this ice_func=1 end function ice_func subroutine ice_sub(a) class(ice_type)::a a%ice_func()=1 ! This is the invalid line end subroutine ice_sub end module ice The marked line is obviously not allowed. When I replace class(ice_type)::a by type(ice_type)::a then get a proper error message, but the class statement results in an internal compiler error. My gfortran version is 4.7.0 20110620
In fact this is a regression: With 4.5 one gets the correct error message.
The fix is pretty trivial: Index: gcc/fortran/expr.c =================================================================== --- gcc/fortran/expr.c (revision 175562) +++ gcc/fortran/expr.c (working copy) @@ -4395,7 +4395,7 @@ gfc_check_vardef_context (gfc_expr* e, bool pointe } if (!pointer && e->expr_type == EXPR_FUNCTION - && sym->result->attr.pointer) + && sym->result && sym->result->attr.pointer) { if (!(gfc_option.allow_std & GFC_STD_F2008)) { With this one gets: a%ice_func()=1 ! This is the invalid line 1 Error: Non-variable expression in variable definition context (assignment) at (1)
Also: Mine. [Will commit as obvious after regtesting.]
For the record: The regression is probably due to r165749: http://gcc.gnu.org/viewcvs?view=revision&revision=165749
Note: You can get the same ICE on *valid* code, if you give the return value of 'ice_func' the POINTER attribute (allowed by F08): module ice type::ice_type contains procedure::ice_func end type ice_type contains pure function ice_func(this) integer, pointer :: ice_func class(ice_type),intent(in)::this ice_func=1 end function ice_func subroutine ice_sub(a) class(ice_type)::a a%ice_func()=1 ! This is valid now end subroutine ice_sub end module ice Unfortunately this test case is rejected with the patch in comment #2.
(In reply to comment #5) > Unfortunately this test case is rejected with the patch in comment #2. However, it is accepted with this improved patch: Index: gcc/fortran/expr.c =================================================================== --- gcc/fortran/expr.c (revision 175580) +++ gcc/fortran/expr.c (working copy) @@ -4394,8 +4394,8 @@ gfc_check_vardef_context (gfc_expr* e, bool pointe sym = e->value.function.esym ? e->value.function.esym : e->symtree->n.sym; } - if (!pointer && e->expr_type == EXPR_FUNCTION - && sym->result->attr.pointer) + attr = gfc_expr_attr (e); + if (!pointer && e->expr_type == EXPR_FUNCTION && attr.pointer) { if (!(gfc_option.allow_std & GFC_STD_F2008)) { @@ -4432,7 +4432,6 @@ gfc_check_vardef_context (gfc_expr* e, bool pointe /* Find out whether the expr is a pointer; this also means following component references to the last one. */ - attr = gfc_expr_attr (e); is_pointer = (attr.pointer || attr.proc_pointer); if (pointer && !is_pointer) {
Author: janus Date: Sat Jul 2 11:08:41 2011 New Revision: 175779 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175779 Log: 2011-07-02 Janus Weil <janus@gcc.gnu.org> PR fortran/49562 * expr.c (gfc_check_vardef_context): Handle type-bound procedures. 2011-07-02 Janus Weil <janus@gcc.gnu.org> PR fortran/49562 * gfortran.dg/typebound_proc_23.f90: New. Added: trunk/gcc/testsuite/gfortran.dg/typebound_proc_23.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/expr.c trunk/gcc/testsuite/ChangeLog
Janus, what's the status of this PR? I think only backporting is missing, is that correct?
(In reply to comment #8) > Janus, what's the status of this PR? > I think only backporting is missing, is that correct? Right. I'm just about to apply the backport ...
Author: janus Date: Sun Jul 10 11:50:04 2011 New Revision: 176117 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=176117 Log: 2011-07-10 Janus Weil <janus@gcc.gnu.org> PR fortran/49562 * expr.c (gfc_check_vardef_context): Handle type-bound procedures. 2011-07-10 Janus Weil <janus@gcc.gnu.org> PR fortran/49562 * gfortran.dg/typebound_proc_23.f90: New. Added: branches/gcc-4_6-branch/gcc/testsuite/gfortran.dg/typebound_proc_23.f90 Modified: branches/gcc-4_6-branch/gcc/fortran/ChangeLog branches/gcc-4_6-branch/gcc/fortran/expr.c branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Fixed on trunk and 4.6. Closing. Also: Thanks for reporting, Hans-Werner!