http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50981
--- Comment #12 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-01-06 11:06:59 UTC --- Draft patch. (It uses gfc_expr_attr to allow for pointer/allocatable components. I also tried to take BT_CLASS into account.) (This patch is a side effect of unsuccessful debugging of the related PR 51758.) --- trans-array.c (revision 182944) +++ trans-array.c (working copy) @@ -8362,9 +8384,17 @@ gfc_walk_elemental_function_args (gfc_ss * ss, gfc if (dummy_arg != NULL && dummy_arg->sym->attr.optional - && arg->expr->symtree - && arg->expr->symtree->n.sym->attr.optional - && arg->expr->ref == NULL) + && arg->expr->expr_type == EXPR_VARIABLE + && ((arg->expr->symtree->n.sym->attr.optional + && arg->expr->ref == NULL) + || ((gfc_expr_attr (arg->expr).allocatable + || gfc_expr_attr (arg->expr).pointer) + && ((dummy_arg->sym->ts.type != BT_CLASS + && !dummy_arg->sym->attr.allocatable + && !dummy_arg->sym->attr.pointer) + || (dummy_arg->sym->ts.type == BT_CLASS + && !CLASS_DATA (dummy_arg->sym)->attr.allocatable + && !CLASS_DATA (dummy_arg->sym)->attr.pointer))))) newss->info->data.scalar.can_be_null_ref = true; } else