From: Janus Weil Date: Tue, 8 Nov 2016 22:07:21 +0000 (+0100) Subject: re PR fortran/68440 ([OOP] ICE on declaring class variable with wrong attribute) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=103c4f759ab75305a7cb7927af6b35b1f5da5f06;p=gcc.git re PR fortran/68440 ([OOP] ICE on declaring class variable with wrong attribute) 2016-11-08 Janus Weil PR fortran/68440 * expr.c (check_alloc_comp_init): Loosen an assert. * resolve.c (resolve_fl_parameter): Reject class parameters. 2016-11-08 Janus Weil PR fortran/68440 * gfortran.dg/class_58.f90: New test. From-SVN: r241979 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index d3c16994cca..499c3d4c4e3 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2016-11-08 Janus Weil + + PR fortran/68440 + * expr.c (check_alloc_comp_init): Loosen an assert. + * resolve.c (resolve_fl_parameter): Reject class parameters. + 2016-11-08 Janus Weil PR fortran/77596 diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index f059c3c1efa..b2ffaae246a 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -2206,7 +2206,7 @@ check_alloc_comp_init (gfc_expr *e) gfc_constructor *ctor; gcc_assert (e->expr_type == EXPR_STRUCTURE); - gcc_assert (e->ts.type == BT_DERIVED); + gcc_assert (e->ts.type == BT_DERIVED || e->ts.type == BT_CLASS); for (comp = e->ts.u.derived->components, ctor = gfc_constructor_first (e->value.constructor); diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 3a4dd1f77e6..f4d346ed0f3 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -14001,6 +14001,15 @@ resolve_fl_parameter (gfc_symbol *sym) &sym->value->where); return false; } + + /* F03:C509,C514. */ + if (sym->ts.type == BT_CLASS) + { + gfc_error ("CLASS variable %qs at %L cannot have the PARAMETER attribute", + sym->name, &sym->declared_at); + return false; + } + return true; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 05159aa4108..2b561e817b0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-11-08 Janus Weil + + PR fortran/68440 + * gfortran.dg/class_58.f90: New test. + 2016-11-08 Uros Bizjak PR target/70799 diff --git a/gcc/testsuite/gfortran.dg/class_58.f90 b/gcc/testsuite/gfortran.dg/class_58.f90 new file mode 100644 index 00000000000..20b601a2f51 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/class_58.f90 @@ -0,0 +1,13 @@ +! { dg-do compile } +! +! PR 68440: [OOP] ICE on declaring class variable with wrong attribute +! +! Contributed by Gerhard Steinmetz + +subroutine s + type t + end type + class(t), parameter :: x = t() ! { dg-error "cannot have the PARAMETER attribute" } + class(t), parameter :: y = x ! { dg-error "cannot have the PARAMETER attribute" } + class(t) :: z = x ! { dg-error "must be dummy, allocatable or pointer" } +end