From patchwork Thu Sep 2 21:44:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: fortran/45495 -- optional dummy args cannot not be in restricted expressions Date: Thu, 02 Sep 2010 11:44:01 -0000 From: Steve Kargl X-Patchwork-Id: 63560 Message-Id: <20100902214401.GA64816@troutmask.apl.washington.edu> To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org A specification expression is an expression with limitations that make it suitable for use in specifications such as length type parameters (C501) and array bounds (R512, R513). R729 specification-expr is scalar-int-expr C710 (R729) The scalar-int-expr shall be a restricted expression. A restricted expression is an expression in which each operation is intrinsic and each primary is ... (2) An object designator with a base object that is a dummy argument that has neither the OPTIONAL nor the INTENT(OUT) attribute, The attach patch enforces the above restriction. It has been built and regression tested on x86_64-*-freebsd. OK for trunk? 2010-09-02 Steven G. Kargl PR fortran/45495 * gfortran.dg/dummy_optional_arg.f90: New test. 2010-09-02 Steven G. Kargl PR fortran/45495 * fortran/expr.c (check_inquiry): Optional dummy argument are not permitted in a restricted expression. Index: gcc/testsuite/gfortran.dg/dummy_optional_arg.f90 =================================================================== --- gcc/testsuite/gfortran.dg/dummy_optional_arg.f90 (revision 0) +++ gcc/testsuite/gfortran.dg/dummy_optional_arg.f90 (revision 0) @@ -0,0 +1,11 @@ +! { dg-do compile } +! PR fortran/45495 +! +! Code originally submitted by Philip Mason +! +function jack(aa) + character(len=*), intent(in) :: aa + optional :: aa + character(len=len(aa)+1) :: jack ! { dg-error "cannot be OPTIONAL" } + jack = '' +end function jack Index: gcc/fortran/expr.c =================================================================== --- gcc/fortran/expr.c (revision 163791) +++ gcc/fortran/expr.c (working copy) @@ -2305,6 +2305,12 @@ check_inquiry (gfc_expr *e, int not_rest && ap->expr->expr_type != EXPR_VARIABLE && check_restricted (ap->expr) == FAILURE) return MATCH_ERROR; + + if (not_restricted == 0 + && ap->expr->expr_type == EXPR_VARIABLE + && ap->expr->symtree->n.sym->attr.optional + && ap->expr->symtree->n.sym->attr.dummy) + return MATCH_NO; } return MATCH_YES;