From bd85b4dd2dd7b00b6342ed1e33fb48035a3dcb61 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Mon, 8 Mar 2021 21:59:20 +0100 Subject: [PATCH] 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. --- gcc/fortran/data.c | 7 +++++++ gcc/testsuite/gfortran.dg/parameter_data.f90 | 13 +++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/parameter_data.f90 diff --git a/gcc/fortran/data.c b/gcc/fortran/data.c index 13e3506dd1e8..25e979301698 100644 --- a/gcc/fortran/data.c +++ b/gcc/fortran/data.c @@ -244,6 +244,13 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr *rvalue, mpz_t index, "array-element nor a scalar-structure-component"; 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; last_ts = &symbol->ts; last_con = NULL; diff --git a/gcc/testsuite/gfortran.dg/parameter_data.f90 b/gcc/testsuite/gfortran.dg/parameter_data.f90 new file mode 100644 index 000000000000..b95f9c906969 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/parameter_data.f90 @@ -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 -- 2.47.3