re PR fortran/47572 ([OOP] Invalid: Allocatable polymorphic with init expression.)
authorJanus Weil <janus@gcc.gnu.org>
Wed, 2 Feb 2011 13:11:50 +0000 (14:11 +0100)
committerJanus Weil <janus@gcc.gnu.org>
Wed, 2 Feb 2011 13:11:50 +0000 (14:11 +0100)
2011-02-02  Janus Weil  <janus@gcc.gnu.org>

PR fortran/47572
* resolve.c (resolve_fl_variable): Handle polymorphic allocatables.

2011-02-02  Janus Weil  <janus@gcc.gnu.org>

PR fortran/47572
* gfortran.dg/class_36.f03: New.

From-SVN: r169520

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

index bb1d89e49fc50dd6246844d4cafe4ff06b9dda7d..2331b973e00cd1b686e7aa671f1fec30ae8f3428 100644 (file)
@@ -1,3 +1,8 @@
+2011-02-02  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/47572
+       * resolve.c (resolve_fl_variable): Handle polymorphic allocatables.
+
 2011-02-01  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/47565
index 2a0fc49571c3bc55ddfca8d24e9b118716d44f6c..7f3734e8269bb8b41a93f164c69bffd2f7903861 100644 (file)
@@ -10063,7 +10063,8 @@ resolve_fl_variable (gfc_symbol *sym, int mp_flag)
   /* Reject illegal initializers.  */
   if (!sym->mark && sym->value)
     {
-      if (sym->attr.allocatable)
+      if (sym->attr.allocatable || (sym->ts.type == BT_CLASS
+                                   && CLASS_DATA (sym)->attr.allocatable))
        gfc_error ("Allocatable '%s' at %L cannot have an initializer",
                   sym->name, &sym->declared_at);
       else if (sym->attr.external)
index 4040f63e79a549ef7240aa9588665e67a720d062..6b460a10efee93d3ce7b31104a120b8d6817f7bb 100644 (file)
@@ -1,3 +1,8 @@
+2011-02-02  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/47572
+       * gfortran.dg/class_36.f03: New.
+
 2011-02-02  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/47566
diff --git a/gcc/testsuite/gfortran.dg/class_36.f03 b/gcc/testsuite/gfortran.dg/class_36.f03
new file mode 100644 (file)
index 0000000..6911f3f
--- /dev/null
@@ -0,0 +1,14 @@
+! { dg-do compile }
+!
+! PR 47572: [OOP] Invalid: Allocatable polymorphic with init expression.
+!
+! Contributed by Edmondo Giovannozzi <edmondo.giovannozzi@gmail.com>
+! cf. http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/763785b16883ed68
+
+program scalar_allocation
+  type test
+    real :: a
+  end type
+  class (test), allocatable :: b = test(3.4)  ! { dg-error "cannot have an initializer" }
+  print *,allocated(b)
+end program