From 3a55c8e248e82f0d64ed8acb85183fefe53cfc0a Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Sat, 26 Jan 2019 20:45:55 +0000 Subject: [PATCH] re PR fortran/57553 ([F08] Valid use of STORAGE_SIZE rejected, bad error message for invalid use) 2019-01-26 Harald Anlauf PR fortran/57553 * expr.c (check_inquiry): Add list of inquiry functions allowed in constant expressions for F2008+. 2019-01-26 Harald Anlauf PR fortran/57553 * gfortran.dg/pr57553.f90: New test. From-SVN: r268303 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/expr.c | 19 ++++++++++++++++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr57553.f90 | 10 ++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr57553.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 5ee82a69365..c1d25260652 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2019-01-26 Harald Anlauf + + PR fortran/57553 + * expr.c (check_inquiry): Add list of inquiry functions allowed in + constant expressions for F2008+. + 2019-01-25 Steven G. Kargl PR fortran/85780 diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 965214b0b2e..a9e7f36c491 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -2515,7 +2515,8 @@ check_init_expr_arguments (gfc_expr *e) static bool check_restricted (gfc_expr *); /* F95, 7.1.6.1, Initialization expressions, (7) - F2003, 7.1.7 Initialization expression, (8) */ + F2003, 7.1.7 Initialization expression, (8) + F2008, 7.1.12 Constant expression, (4) */ static match check_inquiry (gfc_expr *e, int not_restricted) @@ -2539,6 +2540,15 @@ check_inquiry (gfc_expr *e, int not_restricted) "new_line", NULL }; + /* std=f2008+ or -std=gnu */ + static const char *const inquiry_func_gnu[] = { + "lbound", "shape", "size", "ubound", + "bit_size", "len", "kind", + "digits", "epsilon", "huge", "maxexponent", "minexponent", + "precision", "radix", "range", "tiny", + "new_line", "storage_size", NULL + }; + int i = 0; gfc_actual_arglist *ap; @@ -2565,8 +2575,11 @@ check_inquiry (gfc_expr *e, int not_restricted) { name = e->symtree->n.sym->name; - functions = (gfc_option.warn_std & GFC_STD_F2003) - ? inquiry_func_f2003 : inquiry_func_f95; + functions = inquiry_func_gnu; + if (gfc_option.warn_std & GFC_STD_F2003) + functions = inquiry_func_f2003; + if (gfc_option.warn_std & GFC_STD_F95) + functions = inquiry_func_f95; for (i = 0; functions[i]; i++) if (strcmp (functions[i], name) == 0) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4d55dee26b7..d6f6e0f266f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-01-26 Harald Anlauf + + PR fortran/57553 + * gfortran.dg/pr57553.f90: New test. + 2019-01-26 Eric Botcazou * gnat.dg/array34.adb: New test. diff --git a/gcc/testsuite/gfortran.dg/pr57553.f90 b/gcc/testsuite/gfortran.dg/pr57553.f90 new file mode 100644 index 00000000000..afd0cc14d90 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr57553.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! +! PR fortran/57553 - bad error message for invalid use of STORAGE_SIZE +! +! Testcase contributed by Tobias Burnus + +subroutine S (A) + character(len=*), intent(in) :: A + integer, parameter :: ESize = (storage_size(a) + 7) / 8 ! { dg-error "does not reduce to a constant" } +end -- 2.30.2