http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51800

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-01-11 
16:06:26 UTC ---
(In reply to comment #2)
> There is an additional issue for initialization of characters:
>   subroutine sub(n)
>     character(len=n) :: str

That was simpler that I had hoped for:

subroutine foo(n)
  character(len=n) :: str
  print *, str
end subroutine foo

call foo(3)
call foo(10)
end

$ gfortran -finit-character=89 test.f90 && ./a.out
 YYY
 YYYYYYYYYY


--- resolve.c   (revision 183093)
+++ resolve.c   (working copy)
@@ -10143,6 +10143,26 @@ build_default_init_expr (gfc_symbol *sym)
          gfc_free_expr (init_expr);
          init_expr = NULL;
        }
+      if (!init_expr && gfc_option.flag_init_character ==
GFC_INIT_CHARACTER_ON
+         && sym->ts.u.cl->length)
+       {
+         gfc_actual_arglist *arg;
+         init_expr = gfc_get_expr ();
+         init_expr->where = sym->declared_at;
+         init_expr->ts = sym->ts;
+         init_expr->expr_type = EXPR_FUNCTION;
+         init_expr->value.function.isym =
+               gfc_intrinsic_function_by_id (GFC_ISYM_REPEAT);
+         init_expr->value.function.name = "repeat";
+         arg = gfc_get_actual_arglist ();
+         arg->expr = gfc_get_character_expr (sym->ts.kind, &sym->declared_at,
+                                             NULL, 1);
+         arg->expr->value.character.string[0]
+               = gfc_option.flag_init_character_value;
+         arg->next = gfc_get_actual_arglist ();
+         arg->next->expr = gfc_copy_expr (sym->ts.u.cl->length);
+         init_expr->value.function.actual = arg;
+       }
       break;

     default:

Reply via email to