PR fortran/49278 - ICE when combining DATA with default initialization

A variable with the PARAMETER attribute may not appear in a DATA statement.

gcc/fortran/ChangeLog:

	PR fortran/49278
	* data.c (gfc_assign_data_value): Reject variable with PARAMETER
	attribute in DATA statement.

gcc/testsuite/ChangeLog:

	PR fortran/49278
	* gfortran.dg/parameter_data.f90: New test.
This commit is contained in:
Harald Anlauf 2021-03-08 21:59:20 +01:00
parent f3daa6c0fd
commit bd85b4dd2d
2 changed files with 20 additions and 0 deletions

View File

@ -244,6 +244,13 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr *rvalue, mpz_t index,
"array-element nor a scalar-structure-component"; "array-element nor a scalar-structure-component";
symbol = lvalue->symtree->n.sym; symbol = lvalue->symtree->n.sym;
if (symbol->attr.flavor == FL_PARAMETER)
{
gfc_error ("PARAMETER %qs shall not appear in a DATA statement at %L",
symbol->name, &lvalue->where);
return false;
}
init = symbol->value; init = symbol->value;
last_ts = &symbol->ts; last_ts = &symbol->ts;
last_con = NULL; last_con = NULL;

View File

@ -0,0 +1,13 @@
! { dg-do compile }
! PR fortran/49278 - ICE when combining DATA with default initialization
program p
implicit none
type t
real :: a
end type t
integer, parameter :: b = 42
type(t), parameter :: z = t(4.0)
data b / 666 / ! { dg-error "shall not appear in a DATA statement" }
data z%a / 3.0 / ! { dg-error "shall not appear in a DATA statement" }
end