From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 135AD3858413; Thu, 13 Apr 2023 21:28:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 135AD3858413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681421331; bh=VI7HNX+MveuCK4gPDeuRL//RBiOIM+Uw29lJcjhpBXY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=m+7XR9nhpWRMfQ7vf1Mq8L1ei/s7t+CNahZD0MX5DY97MlHGM/paHf8qmjVZ06DOp t9LsaEI1tiXMmPuzF3Unu1TWV5tru75+F5BQg6YTGbOL4Dx6J1T8pQo/b1nEj8amLm tLybw+jjbi2drfaMVW3oOpyuzlJ0XFotXR3WdaV0= From: "anlauf at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/109500] SIGABRT when calling a function that returns an unallocated value Date: Thu, 13 Apr 2023 21:28:50 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: anlauf at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109500 --- Comment #6 from anlauf at gcc dot gnu.org --- (In reply to Leandro Lupori from comment #5) > Ok, thanks for the detailed explanations. Now I see that the standard > doesn't allow the return of an unallocated value. This can be closed as > invalid. >=20 > But may I just ask a last related question? As mentioned in the last comm= ent > and according to Note 1 in F2018 8.5.3 ALLOCATABLE attribute, the result = of > referencing a function cannot be used as an allocatable argument. The precise text is: "... The result of referencing a function whose result variable has the ALLOCATABLE attribute is a value that does not itself have the ALLOCATABLE attribute." So you can add e.g. allocate (f, source=3D42) to the body of f to define the result, and then use it as e.g. integer, allocatable :: p p =3D f() print *, allocated (p) I am still trying to find the exact place in the standard that explains whether - with the corrected f - the following is legal: print *, is_allocated(f()) > This is > however allowed by gfortran (and ifort), with the exception of intrinsic > procedures, and seems to work correctly. Should this be considered an > extension or does it just work by accident and there are no guarantees at > all when using it? I think we are in dangerous waters here. If something appears to work empirically with one compiler, that does not guarantee anything. So as already discussed, if the allocation status of the result cannot be guaranteed, better use a subroutine.=