[Bug fortran/100440] allocated() gives True for unallocated variable

sgk at troutmask dot apl.washington.edu gcc-bugzilla@gcc.gnu.org
Sun May 9 00:32:06 GMT 2021


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

--- Comment #10 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Sat, May 08, 2021 at 06:49:11PM +0000, anlauf at gcc dot gnu.org wrote:
> (In reply to Steve Kargl from comment #7)
> > There is no default initialization in the code below.  default
> > initialization is
> > 
> >   type foo
> >     integer :: i = 1  ! <-- Default initialization
> >   end tyep foo
> 
> The F2018 standard says:
> 
> 7.5.4.6 Default initialization for components
> 
> [...] Allocatable components are always initialized to unallocated.
> 

Interesting choice of wording in the Fortran standard.  Normally,
assigning a value to an entity would mean that it is initialized.

  integer, allocatable :: i
  allocate(i)
  end

Is 'i' initialized?  No.  It is allocated, but undefined.
The ALLOCATED() intrinsic returns the status of its argument
as either allocated (.true.) or unallocated (.false.).  It
does not tell if it is initialized.

In fact, the Fortran Standard states

3.49
default initialization
mechanism for automatically initializing pointer components to have a
defined pointer association status, and nonpointer components to have
a particular value (7.5.4.6)

I'll send a note to J3.


More information about the Gcc-bugs mailing list