From 1813c97a6fd41062e5154e1fb0e7e2cc762306a5 Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Sun, 11 Mar 2018 21:39:15 +0000 Subject: [PATCH] re PR fortran/83939 (Constraint C1290 (elemental function cannot be allocatable) not enforced) 2018-03-11 Steven G. Kargl PR fortran/83939 * resolve.c (resolve_fl_procedure): Enforce F2018:C15100. 2018-03-11 Steven G. Kargl PR fortran/83939 * gfortran.dg/pr83939.f90 From-SVN: r258437 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/resolve.c | 13 +++++++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr83939.f90 | 12 ++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pr83939.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 68e4f38bb85..45def3230da 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ + +2018-03-11 Steven G. Kargl + + PR fortran/83939 + * resolve.c (resolve_fl_procedure): Enforce F2018:C15100. + 2018-03-11 Steven G. Kargl * check.c (gfc_check_kill): Check pid and sig are scalar. diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 6e20184e648..e28146a8bf4 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -12451,6 +12451,19 @@ resolve_fl_procedure (gfc_symbol *sym, int mp_flag) } } + /* F2018, C15100: "The result of an elemental function shall be scalar, + and shall not have the POINTER or ALLOCATABLE attribute." The scalar + pointer is tested and caught elsewhere. */ + if (sym->attr.elemental && sym->result + && (sym->result->attr.allocatable || sym->result->attr.pointer)) + { + gfc_error ("Function result variable %qs at %L of elemental " + "function %qs shall not have an ALLOCATABLE or POINTER " + "attribute", sym->result->name, + &sym->result->declared_at, sym->name); + return false; + } + if (sym->attr.is_bind_c && sym->attr.is_c_interop != 1) { gfc_formal_arglist *curr_arg; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4f7a81663e6..c089a1dc273 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-03-11 Steven G. Kargl + + PR fortran/83939 + * gfortran.dg/pr83939.f90 + 2018-03-11 Thomas Koenig PR fortran/66128 diff --git a/gcc/testsuite/gfortran.dg/pr83939.f90 b/gcc/testsuite/gfortran.dg/pr83939.f90 new file mode 100644 index 00000000000..dfeaac71630 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr83939.f90 @@ -0,0 +1,12 @@ +! { dg-do compile } +elemental function f() result(s) ! { dg-error "shall not have an ALLOCATABLE or POINTER" } + allocatable s + allocate(s) + s = 3.5 +end function + +elemental function g() result(s) ! { dg-error "shall not have an ALLOCATABLE or POINTER" } + pointer s + allocate(s) + s = 3.5 +end function -- 2.30.2