From patchwork Thu Sep 2 21:44:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Kargl X-Patchwork-Id: 63560 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 4476FB7154 for ; Fri, 3 Sep 2010 07:44:12 +1000 (EST) Received: (qmail 9315 invoked by alias); 2 Sep 2010 21:44:08 -0000 Received: (qmail 9295 invoked by uid 22791); 2 Sep 2010 21:44:07 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL, BAYES_05, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from troutmask.apl.washington.edu (HELO troutmask.apl.washington.edu) (128.208.78.105) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 02 Sep 2010 21:44:03 +0000 Received: from troutmask.apl.washington.edu (localhost.apl.washington.edu [127.0.0.1]) by troutmask.apl.washington.edu (8.14.4/8.14.4) with ESMTP id o82Li1Yu064844; Thu, 2 Sep 2010 14:44:01 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.14.4/8.14.4/Submit) id o82Li1CH064843; Thu, 2 Sep 2010 14:44:01 -0700 (PDT) (envelope-from sgk) Date: Thu, 2 Sep 2010 14:44:01 -0700 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] fortran/45495 -- optional dummy args cannot not be in restricted expressions Message-ID: <20100902214401.GA64816@troutmask.apl.washington.edu> Mime-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.4.2.3i Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list 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;