https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98454

--- Comment #8 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
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=98454
> 
> --- Comment #6 from Fran Martinez Fadrique <ffadrique at gmail dot com> ---
> 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 expectations.
> 
> 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 declared
> 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 properly
> initialize the components.

Putting your code in one file.

module m_test

   implicit none

   type t_test
      integer :: unit = -1
      integer :: def
      logical :: trace = .true.
      logical :: def_trace
   end type t_test

   interface test
      module procedure test_default
   end interface  

   contains
      ! INVALID.
      ! Neither def not def_trace are set.  Therefore, res is undefined.
      ! Function result is not defined on return. 
      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      = ', x%unit
   write(6,*) '  default   = ', x%def        ! Invalid.  Undefined component.
   write(6,*) '  trace     = ', x%trace
   write(6,*) '  def trace = ', x%def_trace  ! Invalid.  Undefined component.

   x = 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      = ', x%unit
   write(6,*) '  default   = ', x%def
   write(6,*) '  trace     = ', x%trace
   write(6,*) '  def trace = ', x%def_trace

end program driver_test

> I compile with -std=2018 so I would expect that invalid Fortran is flagged, 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.

Reply via email to