diff mbox

[Fortran] PR54301 - add warning for pointer might outlive its target

Message ID 503286DF.7080203@net-b.de
State New
Headers show

Commit Message

Tobias Burnus Aug. 20, 2012, 6:50 p.m. UTC
Hi Thomas,

Thomas Koenig wrote:
> do you think that -Wtarget-lifetime should be included with -Wall?
> I think so, because the code flagged is certainly invalid, and likely
> to cause random errors.

I concur. However, that's what the current version in the trunk does: 
-Wall implies -Wtarget-lifetime.

On the other hand, I just realized that "attr.result" is not set if the 
function symbols is also its result symbol – hence, there is no warning for:

function f()
   integer, pointer :: f
   integer, target :: t
   f => t
end

I think the following patch will fix that. I will package, regtest and 
commit it later.

Tobias

              || lvalue->symtree->n.sym->attr.in_common;
diff mbox

Patch

--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -3673,6 +3673,7 @@  gfc_check_pointer_assign (gfc_expr *lvalue, 
gfc_expr *rvalue)

        warn = lvalue->symtree->n.sym->attr.dummy
              || lvalue->symtree->n.sym->attr.result
+            || lvalue->symtree->n.sym->attr.function
              || lvalue->symtree->n.sym->attr.host_assoc
              || lvalue->symtree->n.sym->attr.use_assoc