http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51208
--- Comment #3 from Steve Kargl <sgk at troutmask dot apl.washington.edu> 2011-11-18 18:40:31 UTC --- On Fri, Nov 18, 2011 at 04:03:04PM +0000, burnus at gcc dot gnu.org wrote: > > Well, it is not. One can restrict one to the common case of expr->expr_type == > EXPR_VARIABLE and just do the same as for STAT=: Checking whether the variable > is the same. > > Will that catch all wrong usage? No, but it will catch the most common mistake > of choosing the wrong variable. That's as illustrated above the same with > STAT=. > > I am sure that Intel's compiler does not do anything more advanced - and it > would have found the mistake I made in PR 51207. > Although I think this is equilavent to putting a bandaid on a AK-47 bullet hole, here you go troutmask:sgk[246] cat foo.f90 program foo use bar allocate(x(2), source=x) end program foo troutmask:sgk[245] gfc4x -o z -Wall -Wextra foo.f90 foo.f90:4.11-24: allocate(x(2), source=x) 1 2 Error: Allocate-object at (1) shall not appear in a source-expr or mold-expr at (2) Index: resolve.c =================================================================== --- resolve.c (revision 181489) +++ resolve.c (working copy) @@ -7173,6 +7173,38 @@ resolve_allocate_deallocate (gfc_code *c } } + /* If source-expr or mold-expr is a variable, check that it + is not an alloc-object. */ + if (code->expr3 && code->expr3->expr_type == EXPR_VARIABLE) + { + for (p = code->ext.alloc.list; p; p = p->next) + if (p->expr->symtree->n.sym->name == code->expr3->symtree->n.sym->name) + { + gfc_ref *ref1, *ref2; + bool found = true; + + for (ref1 = p->expr->ref, ref2 = code->expr3->ref; ref1 && ref2; + ref1 = ref1->next, ref2 = ref2->next) + { + if (ref1->type != REF_COMPONENT || ref2->type != REF_COMPONENT) + continue; + if (ref1->u.c.component->name != ref2->u.c.component->name) + { + found = false; + break; + } + } + + if (found) + { + gfc_error ("Allocate-object at %L shall not appear in a " + "source-expr or mold-expr at %L", + &p->expr->where, &code->expr3->where); + break; + } + } + } + /* Check that an allocate-object appears only once in the statement. FIXME: Checking derived types is disabled. */ for (p = code->ext.alloc.list; p; p = p->next)