From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) by sourceware.org (Postfix) with ESMTPS id 07735396D809 for ; Wed, 16 Nov 2022 20:24:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 07735396D809 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=troutmask.apl.washington.edu Authentication-Results: sourceware.org; spf=none smtp.mailfrom=troutmask.apl.washington.edu Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.16.1/8.16.1) with ESMTPS id 2AGKOPmp074804 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO) for ; Wed, 16 Nov 2022 12:24:25 -0800 (PST) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.16.1/8.16.1/Submit) id 2AGKOPxL074803 for fortran@gcc.gnu.org; Wed, 16 Nov 2022 12:24:25 -0800 (PST) (envelope-from sgk) Date: Wed, 16 Nov 2022 12:24:25 -0800 From: Steve Kargl To: Steve Kargl via Fortran Subject: Re: typespec in forall and implied-do Message-ID: Reply-To: sgk@troutmask.apl.washington.edu References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, Nov 15, 2022 at 06:31:16PM -0800, Steve Kargl via Fortran wrote: > On Tue, Nov 15, 2022 at 05:13:19PM -0800, Steve Kargl via Fortran wrote: > > F2008 introduced the inclusion of a typespec in a forall > > statement, and thn F2018 a typespec was allowed in an > > implied-do. There may even be a few bug reports. > > > > Forgot to ask. Anyone know how namespaces work with > initialization expressions in gfortran? This code > should compile > > program foo > use iso_fortran_env, only : k => real_kinds > implicit none > integer, parameter :: n = size(k) > integer, parameter :: & > & p(n) = [(precision(real(1.,k(i))), integer :: i = 1, n)] > print '(*(I0,X))', p > end program foo > > > The first occurence of 'i' in the expression for 'p(n)' > is either thought to be in a different namespace, or > an implied-do loop cannot be used in an initialization > expression. After spending to much time on this, I found that decl.cc:3044-50 m = gfc_match_init_expr (&initializer); if (m == MATCH_NO) { gfc_error ("Expected an initialization expression at %C"); m = MATCH_ERROR; } results in m == MATCH_ERROR. First, I would expect the "if" condition to include the m == MATCH_ERROR to generate an error message. Second, an implied-do loop can appear in an initialization expression. So, gfortran is not handling this correctly. Now, if one goes to expr.cc:gfc_match_init_expr, gfortran matches the RHS expression, but gfc_reduce_init_expr() fails to expand the array constructor. -- Steve