Commit 83ba23b7 by Tobias Burnus Committed by Tobias Burnus

re PR fortran/43366 ([OOP][F08] Intrinsic assign to polymorphic variable)

2013-09-15  Tobias Burnus  <burnus@net-b.de>

        PR fortran/43366
        * primary.c (gfc_variable_attr): Also handle codimension.
        * resolve.c (resolve_ordinary_assign): Add invalid-diagnostic
        * for
        polymorphic assignment.

2013-09-15  Tobias Burnus  <burnus@net-b.de>

        PR fortran/43366
        * gfortran.dg/class_39.f03: Update dg-error.
        * gfortran.dg/class_5.f03: Ditto.
        * gfortran.dg/class_53.f90: Ditto.
        * gfortran.dg/realloc_on_assign_20.f90: New.
        * gfortran.dg/realloc_on_assign_21.f90: New.
        * gfortran.dg/realloc_on_assign_22.f90: New.

From-SVN: r202713
parent 3f3fd87d
2013-09-18 Tobias Burnus <burnus@net-b.de>
PR fortran/43366
* primary.c (gfc_variable_attr): Also handle codimension.
* resolve.c (resolve_ordinary_assign): Add invalid-diagnostic for
polymorphic assignment.
2013-09-16 Tobias Burnus <burnus@net-b.de> 2013-09-16 Tobias Burnus <burnus@net-b.de>
PR fortran/58356 PR fortran/58356
......
...@@ -2134,7 +2134,7 @@ check_substring: ...@@ -2134,7 +2134,7 @@ check_substring:
symbol_attribute symbol_attribute
gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts) gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts)
{ {
int dimension, pointer, allocatable, target; int dimension, codimension, pointer, allocatable, target;
symbol_attribute attr; symbol_attribute attr;
gfc_ref *ref; gfc_ref *ref;
gfc_symbol *sym; gfc_symbol *sym;
...@@ -2149,12 +2149,14 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts) ...@@ -2149,12 +2149,14 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts)
if (sym->ts.type == BT_CLASS && sym->attr.class_ok) if (sym->ts.type == BT_CLASS && sym->attr.class_ok)
{ {
dimension = CLASS_DATA (sym)->attr.dimension; dimension = CLASS_DATA (sym)->attr.dimension;
codimension = CLASS_DATA (sym)->attr.codimension;
pointer = CLASS_DATA (sym)->attr.class_pointer; pointer = CLASS_DATA (sym)->attr.class_pointer;
allocatable = CLASS_DATA (sym)->attr.allocatable; allocatable = CLASS_DATA (sym)->attr.allocatable;
} }
else else
{ {
dimension = attr.dimension; dimension = attr.dimension;
codimension = attr.codimension;
pointer = attr.pointer; pointer = attr.pointer;
allocatable = attr.allocatable; allocatable = attr.allocatable;
} }
...@@ -2209,11 +2211,13 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts) ...@@ -2209,11 +2211,13 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts)
if (comp->ts.type == BT_CLASS) if (comp->ts.type == BT_CLASS)
{ {
codimension = CLASS_DATA (comp)->attr.codimension;
pointer = CLASS_DATA (comp)->attr.class_pointer; pointer = CLASS_DATA (comp)->attr.class_pointer;
allocatable = CLASS_DATA (comp)->attr.allocatable; allocatable = CLASS_DATA (comp)->attr.allocatable;
} }
else else
{ {
codimension = comp->attr.codimension;
pointer = comp->attr.pointer; pointer = comp->attr.pointer;
allocatable = comp->attr.allocatable; allocatable = comp->attr.allocatable;
} }
...@@ -2228,6 +2232,7 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts) ...@@ -2228,6 +2232,7 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts)
} }
attr.dimension = dimension; attr.dimension = dimension;
attr.codimension = codimension;
attr.pointer = pointer; attr.pointer = pointer;
attr.allocatable = allocatable; attr.allocatable = allocatable;
attr.target = target; attr.target = target;
......
...@@ -9014,6 +9014,7 @@ resolve_ordinary_assign (gfc_code *code, gfc_namespace *ns) ...@@ -9014,6 +9014,7 @@ resolve_ordinary_assign (gfc_code *code, gfc_namespace *ns)
int rlen = 0; int rlen = 0;
int n; int n;
gfc_ref *ref; gfc_ref *ref;
symbol_attribute attr;
if (gfc_extend_assign (code, ns)) if (gfc_extend_assign (code, ns))
{ {
...@@ -9178,14 +9179,35 @@ resolve_ordinary_assign (gfc_code *code, gfc_namespace *ns) ...@@ -9178,14 +9179,35 @@ resolve_ordinary_assign (gfc_code *code, gfc_namespace *ns)
gfc_current_ns->proc_name->attr.implicit_pure = 0; gfc_current_ns->proc_name->attr.implicit_pure = 0;
} }
/* F03:7.4.1.2. */ /* F2008, 7.2.1.2. */
/* FIXME: Valid in Fortran 2008, unless the LHS is both polymorphic attr = gfc_expr_attr (lhs);
and coindexed; cf. F2008, 7.2.1.2 and PR 43366. */ if (lhs->ts.type == BT_CLASS && attr.allocatable)
if (lhs->ts.type == BT_CLASS) {
if (attr.codimension)
{
gfc_error ("Assignment to polymorphic coarray at %L is not "
"permitted", &lhs->where);
return false;
}
if (!gfc_notify_std (GFC_STD_F2008, "Assignment to an allocatable "
"polymorphic variable at %L", &lhs->where))
return false;
if (!gfc_option.flag_realloc_lhs)
{
gfc_error ("Assignment to an allocatable polymorphic variable at %L "
"requires -frealloc-lhs", &lhs->where);
return false;
}
/* See PR 43366. */
gfc_error ("Assignment to an allocatable polymorphic variable at %L "
"is not yet supported", &lhs->where);
return false;
}
else if (lhs->ts.type == BT_CLASS)
{ {
gfc_error ("Variable must not be polymorphic in intrinsic assignment at " gfc_error ("Nonallocatable variable must not be polymorphic in intrinsic "
"%L - check that there is a matching specific subroutine " "assignment at %L - check that there is a matching specific "
"for '=' operator", &lhs->where); "subroutine for '=' operator", &lhs->where);
return false; return false;
} }
......
2013-09-18 Tobias Burnus <burnus@net-b.de>
PR fortran/43366
* gfortran.dg/class_39.f03: Update dg-error.
* gfortran.dg/class_5.f03: Ditto.
* gfortran.dg/class_53.f90: Ditto.
* gfortran.dg/realloc_on_assign_20.f90: New.
* gfortran.dg/realloc_on_assign_21.f90: New.
* gfortran.dg/realloc_on_assign_22.f90: New.
2013-09-18 Paolo Carlini <paolo.carlini@oracle.com> 2013-09-18 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/58457 PR c++/58457
......
...@@ -8,6 +8,6 @@ ...@@ -8,6 +8,6 @@
end type T end type T
contains contains
class(T) function add() ! { dg-error "must be dummy, allocatable or pointer" } class(T) function add() ! { dg-error "must be dummy, allocatable or pointer" }
add = 1 ! { dg-error "Variable must not be polymorphic in intrinsic assignment" } add = 1 ! { dg-error "Nonallocatable variable must not be polymorphic in intrinsic assignment" }
end function end function
end end
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
x = t2(45,478) x = t2(45,478)
allocate(t2 :: cp) allocate(t2 :: cp)
cp = x ! { dg-error "Variable must not be polymorphic" } cp = x ! { dg-error "Nonallocatable variable must not be polymorphic" }
select type (cp) select type (cp)
type is (t2) type is (t2)
...@@ -28,4 +28,3 @@ ...@@ -28,4 +28,3 @@
end select end select
end end
\ No newline at end of file
...@@ -13,6 +13,6 @@ end type ...@@ -13,6 +13,6 @@ end type
type(arr_t) :: this type(arr_t) :: this
class(arr_t) :: elem ! { dg-error "must be dummy, allocatable or pointer" } class(arr_t) :: elem ! { dg-error "must be dummy, allocatable or pointer" }
elem = this ! { dg-error "Variable must not be polymorphic in intrinsic assignment" } elem = this ! { dg-error "Nonallocatable variable must not be polymorphic in intrinsic assignment" }
end end
! { dg-do compile }
! { dg-options "-std=f2003" }
!
! PR fortran/43366
!
! Invalid assignment to an allocatable polymorphic var.
!
type t
end type t
class(t), allocatable :: var
var = t() ! { dg-error "Fortran 2008: Assignment to an allocatable polymorphic variable" }
end
! { dg-do compile }
! { dg-options "-fno-realloc-lhs" }
!
! PR fortran/43366
!
! Invalid assignment to an allocatable polymorphic var.
!
type t
end type t
class(t), allocatable :: var
var = t() ! { dg-error "Assignment to an allocatable polymorphic variable at .1. requires -frealloc-lhs" }
end
! { dg-do compile }
! { dg-options "-fcoarray=single" }
!
! PR fortran/43366
!
! Invalid assignment to an allocatable polymorphic var.
!
type t
end type t
class(t), allocatable :: caf[:]
caf = t() ! { dg-error "Assignment to polymorphic coarray at .1. is not permitted" }
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment