From b349a81aa03c74c0d39fb5ac847c308ab63be76e Mon Sep 17 00:00:00 2001 From: Janus Weil Date: Wed, 9 Nov 2016 18:22:02 +0100 Subject: [PATCH] [multiple changes] 2016-11-09 Steve Kargl Janus Weil PR fortran/60777 * expr.c (external_spec_function): Allow recursive specification functions in F03. 2016-11-09 Janus Weil PR fortran/60777 * gfortran.dg/spec_expr_7.f90: New test. From-SVN: r242009 --- gcc/fortran/ChangeLog | 7 +++++ gcc/fortran/expr.c | 10 +++---- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gfortran.dg/spec_expr_7.f90 | 34 +++++++++++++++++++++++ 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/spec_expr_7.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index bb0beb713e9..615ade012f7 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2016-11-09 Steve Kargl + Janus Weil + + PR fortran/60777 + * expr.c (external_spec_function): Allow recursive specification + functions in F03. + 2016-11-09 Paul Thomas * check.c (gfc_check_move_alloc): Prevent error that avoids diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index b2ffaae246a..e2d1311d1a5 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -2794,12 +2794,12 @@ external_spec_function (gfc_expr *e) return false; } - if (f->attr.recursive) - { - gfc_error ("Specification function %qs at %L cannot be RECURSIVE", - f->name, &e->where); + /* F08:7.1.11.6. */ + if (f->attr.recursive + && !gfc_notify_std (GFC_STD_F2003, + "Specification function '%s' " + "at %L cannot be RECURSIVE", f->name, &e->where)) return false; - } function_allowed: return restricted_args (e->value.function.actual); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7a3b6c5ffc6..749c7d6bef0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-11-09 Janus Weil + + PR fortran/60777 + * gfortran.dg/spec_expr_7.f90: New test. + 2016-11-09 Jakub Jelinek PR target/77718 diff --git a/gcc/testsuite/gfortran.dg/spec_expr_7.f90 b/gcc/testsuite/gfortran.dg/spec_expr_7.f90 new file mode 100644 index 00000000000..0680d1207a8 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/spec_expr_7.f90 @@ -0,0 +1,34 @@ +! { dg-do run } +! +! PR 60777: [F03] RECURSIVE function rejected in specification expression +! +! Contributed by Vladimir Fuka + +module recur + implicit none +contains + + pure recursive function f(n) result(answer) + integer, intent(in) :: n + integer :: answer + if (n<2) then + answer = 1 + else + answer = f(n-1)*n + end if + end function + + pure function usef(n) + integer,intent(in) :: n + character(f(n)) :: usef + usef = repeat('*',f(n)) + end function +end module + +program testspecexpr + use recur + implicit none + if (usef(1) /= '*') call abort() + if (usef(2) /= '**') call abort() + if (usef(3) /= '******') call abort() +end -- 2.30.2