This is the mail archive of the
mailing list for the GNU Fortran project.
Re: [Patch, Fortran, OOP] PR 44541: wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD
On 09/01/2010 06:37 PM, Janus Weil wrote:
Actually I only copied this from the BT_DERIVED case, assuming this
condition would be the same for both. So probably we should also
change this for BT_DERIVED dummies, right? How about:
I thought I saw about a year ago a PR that gfortran _warns_ if one does
not assign to an INTENT(OUT) variable - as the value is set. I thus
think gfortran most of the time already initializes BT_DERIVED variables.
@@ -12179,7 +12148,6 @@ resolve_symbol (gfc_symbol *sym)
described in 14.7.5, to those variables that have not already
been assigned one. */
if (sym->ts.type == BT_DERIVED
&& sym->ns == gfc_current_ns
That looks fine but ...
@@ -12187,13 +12155,17 @@ resolve_symbol (gfc_symbol *sym)
symbol_attribute *a =&sym->attr;
- if ((!a->save&& !a->dummy&& !a->pointer
+ if ((!a->save&& !a->dummy&& !a->pointer&& a->referenced
&& !a->in_common&& !a->use_assoc
&& !(a->function&& sym != sym->result))
|| (a->dummy&& a->intent == INTENT_OUT&& !a->pointer))
I don't think that's correct: We do not want to default initialize
unused (local) variables. Only dummy arguments - and there is no
a->referenced check for them.
The question is: Why are INTENT(OUT) variables already assigned a value?
I do not want to change the code until one has understood, why the
following currently works - or until one has found an example which
fails the the current code. The following example prints "1":
integer :: i = 1
end type t
type(t) :: a
a%i = 8
print *, a
type(t), intent(out) :: x
+ if (sym->ts.type == BT_CLASS&& sym->ns == gfc_current_ns
+&& sym->attr.dummy&& sym->attr.intent == INTENT_OUT)
+ apply_default_init (sym);
As in the BT_DERIVED checks above, you probably should also check for
!pointer and !allocatable.