summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJanus Weil <janus@gcc.gnu.org>2010-12-29 17:14:11 +0100
committerJanus Weil <janus@gcc.gnu.org>2010-12-29 17:14:11 +0100
commitfbd30c381c53eb734642603671fadfa9120afecd (patch)
treeaa1f5f816e9af0d6122fd72eb434ce66f347d509 /gcc
parentbc81f55980f7c3652a4f9c838c4ff6e825f92e5a (diff)
downloadgcc-fbd30c381c53eb734642603671fadfa9120afecd.tar.gz
re PR fortran/46838 ([OOP] Initialization of polymorphic allocatable components)
2010-12-29 Janus Weil <janus@gcc.gnu.org> PR fortran/46838 * expr.c (gfc_default_initializer): Handle allocatable CLASS components. 2010-12-29 Janus Weil <janus@gcc.gnu.org> PR fortran/46838 * gfortran.dg/alloc_comp_class_2.f90: New. From-SVN: r168322
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/ChangeLog5
-rw-r--r--gcc/fortran/expr.c6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/alloc_comp_class_2.f9029
4 files changed, 43 insertions, 2 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 8fc74f8ca63..759db8311bd 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,8 @@
+2010-12-29 Janus Weil <janus@gcc.gnu.org>
+
+ PR fortran/46838
+ * expr.c (gfc_default_initializer): Handle allocatable CLASS components.
+
2010-12-29 Thomas Koenig <tkoenig@gcc.gnu.org>
* frontend-passes.c (gfc_code_walker): Handle expressions
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index a22e6602a9a..a222ff20fac 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -3648,7 +3648,8 @@ gfc_default_initializer (gfc_typespec *ts)
/* See if we have a default initializer in this, but not in nested
types (otherwise we could use gfc_has_default_initializer()). */
for (comp = ts->u.derived->components; comp; comp = comp->next)
- if (comp->initializer || comp->attr.allocatable)
+ if (comp->initializer || comp->attr.allocatable
+ || (comp->ts.type == BT_CLASS && CLASS_DATA (comp)->attr.allocatable))
break;
if (!comp)
@@ -3665,7 +3666,8 @@ gfc_default_initializer (gfc_typespec *ts)
if (comp->initializer)
ctor->expr = gfc_copy_expr (comp->initializer);
- if (comp->attr.allocatable)
+ if (comp->attr.allocatable
+ || (comp->ts.type == BT_CLASS && CLASS_DATA (comp)->attr.allocatable))
{
ctor->expr = gfc_get_expr ();
ctor->expr->expr_type = EXPR_NULL;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 4e245c9467c..49cf9fcae42 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2010-12-29 Janus Weil <janus@gcc.gnu.org>
+
+ PR fortran/46838
+ * gfortran.dg/alloc_comp_class_2.f90: New.
+
2010-12-29 Thomas Koenig <tkoenig@gcc.gnu.org>
* gfortran.dg/character_comparison_7.f90: New test.
diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_class_2.f90 b/gcc/testsuite/gfortran.dg/alloc_comp_class_2.f90
new file mode 100644
index 00000000000..71862818951
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/alloc_comp_class_2.f90
@@ -0,0 +1,29 @@
+! { dg-do run }
+!
+! PR 46838: [OOP] Initialization of polymorphic allocatable components
+!
+! Contributed by Salvatore Filippone <sfilippone@uniroma2.it>
+
+program bug28
+
+ implicit none
+
+ type indx_map
+ end type
+
+ type desc_type
+ integer, allocatable :: matrix_data
+ class(indx_map), allocatable :: indxmap
+ end type
+
+ type(desc_type) :: desc_a
+ call cdall(desc_a)
+
+contains
+
+ subroutine cdall(desc)
+ type(desc_type), intent(out) :: desc
+ if (allocated(desc%indxmap)) call abort()
+ end subroutine cdall
+
+end program