Hi all, here is a patch for automatic deallocation of allocatable scalars. There are four cases to take care of (which correspond to the subroutines 'a' to 'd' in the test case): 1) plain allocatable scalar variables 2) allocatable scalar CLASS variables 3) allocatable scalar components 4) allocatable scalar CLASS components All of them work fine now AFAICS. One aside, however: There is a strange thing in the dump for case 'c' (not necessarily connected to this patch): struct t1 m; m.j = 0B; { struct t1 D.1388; struct t1 t1.0; t1.0.pi = 3.1400001049041748046875e+0; t1.0.j = 0B; D.1388 = m; m = t1.0; if (D.1388.j != 0B) { __builtin_free ((void *) D.1388.j); } D.1388.j = 0B; } If I'm not mistaken, this code was generated by "gfc_init_default_dt" to handle the default initialization of the variable 'm'. But it's not quite clear to me why we need two temporaries here, or why this 'D.1388' needs to be freed although it's barely used at all (and certainly not allocated). Maybe someone can enlighten me on this matter. The patch was regtested on x86_64-unknown-linux-gnu. Ok for trunk? Cheers, Janus 2009-10-19 Janus Weil PR fortran/41586 * parse.c (parse_derived): Correctly set 'alloc_comp' and 'pointer_comp' for CLASS variables. * trans-array.c (structure_alloc_comps): Handle deallocation and nullification of allocatable scalar components. * trans-decl.c (gfc_get_symbol_decl): Remember allocatable scalars for automatic deallocation. (gfc_trans_deferred_vars): Automatically deallocate allocatable scalars. 2009-10-19 Janus Weil PR fortran/41586 * gfortran.dg/auto_dealloc_1.f90: New test case.