]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/45577 (Bogus(?) "... type incompatible with source-expr ..." error)
authorJanus Weil <janus@gcc.gnu.org>
Wed, 15 Sep 2010 13:50:15 +0000 (15:50 +0200)
committerJanus Weil <janus@gcc.gnu.org>
Wed, 15 Sep 2010 13:50:15 +0000 (15:50 +0200)
2010-09-15  Janus Weil  <janus@gcc.gnu.org>

PR fortran/45577
* resolve.c (resolve_allocate_expr): Do default initialization via
EXEC_INIT_ASSIGN.

2010-09-15  Janus Weil  <janus@gcc.gnu.org>

PR fortran/45577
* gfortran.dg/allocate_derived_4.f90: New.

From-SVN: r164305

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/allocate_derived_4.f90 [new file with mode: 0644]

index e7f79bdedaeb655105ed5fb4b72b0a26675a00c8..10e4ce21423b79d4d63a56b6f3965601a9f69897 100644 (file)
@@ -1,3 +1,9 @@
+2010-09-15  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/45577
+       * resolve.c (resolve_allocate_expr): Do default initialization via
+       EXEC_INIT_ASSIGN.
+
 2010-09-11  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
        * mathbuiltins.def: Do not defined huge_val built-in.
index 90d80a7fda0e87cf25de95605c88f637e447b7d2..2d5e04f22d5f58a20ce4ef14d792ff8d07d550f9 100644 (file)
@@ -6697,10 +6697,16 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code)
       if (ts.type == BT_CLASS)
        ts = ts.u.derived->components->ts;
 
-      if (ts.type == BT_DERIVED)
-       {
-         code->expr3 = gfc_default_initializer (&ts);
-         gfc_resolve_expr (code->expr3);
+      if (ts.type == BT_DERIVED && gfc_has_default_initializer(ts.u.derived))
+       {
+         gfc_expr *init_e = gfc_default_initializer (&ts);
+         gfc_code *init_st = gfc_get_code ();
+         init_st->loc = code->loc;
+         init_st->op = EXEC_INIT_ASSIGN;
+         init_st->expr1 = gfc_expr_to_initialize (e);
+         init_st->expr2 = init_e;
+         init_st->next = code->next;
+         code->next = init_st;
        }
     }
   else if (code->expr3->mold && code->expr3->ts.type == BT_DERIVED)
index 0aaea14ebaf532ab51321df378434afe41578808..c67d3e3404cc27ab0622829bbfc501a2fc440aee 100644 (file)
@@ -1,3 +1,8 @@
+2010-09-15  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/45577
+       * gfortran.dg/allocate_derived_4.f90: New.
+
 2010-09-15  Tejas Belagod  <tejas.belagod@arm.com>
 
        * lib/target-supports.exp
diff --git a/gcc/testsuite/gfortran.dg/allocate_derived_4.f90 b/gcc/testsuite/gfortran.dg/allocate_derived_4.f90
new file mode 100644 (file)
index 0000000..06d1270
--- /dev/null
@@ -0,0 +1,19 @@
+! { dg-do compile }
+!
+! PR 45577: [4.6 Regression] Bogus(?) "... type incompatible with source-expr ..." error
+!
+! Contributed by Dominique d'Humieres <dominiq@lps.ens.fr>
+
+program main
+
+type b_obj
+  integer,allocatable :: c(:)
+  real :: r = 5.
+end type b_obj
+
+type (b_obj),allocatable :: b(:)
+integer,allocatable :: c(:)
+
+allocate(b(3),c(3))
+
+end program main