Dear all,
the middle end does not like to fold_convert a real number to an
integer, but gfortran does not type-convert the expressions of
initialization expressions. This patch fixes the issue - and thus part
of of the issue of the PR.
Build and regtested on x86-64-linux.
OK for the trunk?
Tobias
2012-01-22 Tobias Burnus <bur...@net-b.de>
PR fortran/41600
* expr.c (gfc_default_initializer): Convert the values if
the type does not match.
2012-01-22 Tobias Burnus <bur...@net-b.de>
PR fortran/41600
* gfortran.dg/default_initialization_6.f90: New.
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 7cea780..8565b81 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -3774,7 +3780,13 @@ gfc_default_initializer (gfc_typespec *ts)
gfc_constructor *ctor = gfc_constructor_get();
if (comp->initializer)
- ctor->expr = gfc_copy_expr (comp->initializer);
+ {
+ ctor->expr = gfc_copy_expr (comp->initializer);
+ if ((comp->ts.type != comp->initializer->ts.type
+ || comp->ts.kind != comp->initializer->ts.kind)
+ && !comp->attr.pointer && !comp->attr.proc_pointer)
+ gfc_convert_type_warn (ctor->expr, &comp->ts, 2, false);
+ }
if (comp->attr.allocatable
|| (comp->ts.type == BT_CLASS && CLASS_DATA (comp)->attr.allocatable))
--- /dev/null 2012-01-22 08:37:16.127677872 +0100
+++ gcc/gcc/testsuite/gfortran.dg/default_initialization_6.f90 2012-01-22 15:46:16.000000000 +0100
@@ -0,0 +1,11 @@
+! { dg-do compile }
+!
+! PR fortran/41600
+!
+ implicit none
+ type t
+ integer :: X = -999.0
+ end type t
+ class(t), allocatable :: y(:)
+ allocate (t :: y(1))
+end