From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 14CC0387084C; Sun, 27 Dec 2020 23:07:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14CC0387084C From: "sgk at troutmask dot apl.washington.edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/98454] Apparent wrong initialization in function result Date: Sun, 27 Dec 2020 23:07:37 +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: 9.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sgk at troutmask dot apl.washington.edu X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P4 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Dec 2020 23:07:38 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98454 --- Comment #8 from Steve Kargl -= -- On Sun, Dec 27, 2020 at 10:15:56PM +0000, ffadrique at gmail dot com wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98454 >=20 > --- Comment #6 from Fran Martinez Fadrique -= -- > I have raised the issue with respect to 4.5.3.4 of the ISO standard that > stablishes how the type component are initialized. Not just my expectatio= ns. >=20 > I have further developed my test case and any local variable declared in = any > function or subroutine in the scope of the module where the type is decla= red > fails to properly initialize its components according to the default > initializations (using the terminology of the standard). The intent(out) = seems > to make the difference and subroutine parameters are properly initialized. > Any variable created outside the module declaring the type seems to prope= rly > initialize the components. Putting your code in one file. module m_test implicit none type t_test integer :: unit =3D -1 integer :: def logical :: trace =3D .true. logical :: def_trace end type t_test interface test module procedure test_default end interface=20=20 contains ! INVALID. ! Neither def not def_trace are set. Therefore, res is undefined. ! Function result is not defined on return.=20 function test_default() result(res) type(t_test) :: res end function test_default end module m_test program driver_test use m_test implicit none type(t_test) :: x write(6,*) 'Before constructor' write(6,*) ' unit =3D ', x%unit write(6,*) ' default =3D ', x%def ! Invalid. Undefined compon= ent. write(6,*) ' trace =3D ', x%trace write(6,*) ' def trace =3D ', x%def_trace ! Invalid. Undefined compon= ent. x =3D test() ! Invalid. ! All of the following can be anything as x is defined (and use defined ! here loosely) with an ! undefined function result. write(6,*) 'After constructor' write(6,*) ' unit =3D ', x%unit write(6,*) ' default =3D ', x%def write(6,*) ' trace =3D ', x%trace write(6,*) ' def trace =3D ', x%def_trace end program driver_test > I compile with -std=3D2018 so I would expect that invalid Fortran is flag= ged, at > least with a warning, which is not the case. The Fortran standard likely does not require a Fortran processor to detect the above programmer errors.=