------- Comment #11 from burnus at gcc dot gnu dot org 2009-10-28 15:47 -------
Related problem:
print *, loc(f2(a)) ! OK
print *, loc(f (a)) ! Error "must be a variable"
The second line uses a generic function with "f2" being the specific one.
The problem is that gfc_check_loc calls check_variable, which checks whether
function name = result name. I think this check is bogus. I think the purpose
is to allow:
function_name = value ! in "function function_name" !
but for
value = function_name(bar) ! or LOC(function_name(bar))
it does not matter whether sym == sym->result.
On the other hand, if one is outside of "function function_name"
func(function_name)
is something different (= function and not result) and there it does not matter
whether sym == sym->result or not.
For the the example above, the patch below fixes it, but see caveat above.
Index: check.c
===================================================================
--- check.c (revision 153645)
+++ check.c (working copy)
@@ -288,7 +288,10 @@ variable_check (gfc_expr *e, int n)
if ((e->expr_type == EXPR_VARIABLE
&& e->symtree->n.sym->attr.flavor != FL_PARAMETER)
|| (e->expr_type == EXPR_FUNCTION
- && e->symtree->n.sym->result == e->symtree->n.sym))
+ && ((!e->value.function.esym
+ && e->value.function.esym->result == e->value.function.esym)
+ || (e->value.function.esym
+ && e->symtree->n.sym->result == e->symtree->n.sym))))
return SUCCESS;
if (e->expr_type == EXPR_VARIABLE
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41777