public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libfortran/46182] New: Run time check for invalid use of unallocated allocatable variables
@ 2010-10-26 12:17 dominiq at lps dot ens.fr
  2010-10-26 13:18 ` Mikael Morin
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: dominiq at lps dot ens.fr @ 2010-10-26 12:17 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46182

           Summary: Run time check for invalid use of unallocated
                    allocatable variables
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: libfortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: dominiq@lps.ens.fr


While the following code

type b
  integer, allocatable :: i(:)
end type b
type(b), allocatable :: a(:)
!allocate(a(10))
print *, allocated(a)!, allocated(a(1)%i)
!deallocate(a)
end

seems to be a valid f2003 code and gives 'F' at run time, replacing

print *, allocated(a)!, allocated(a(1)%i)

with

print *, allocated(a), allocated(a(1)%i)

gives a "Segmentation fault" at run time (it gives 'T F' if the
allocate/deallocate lines are uncommented).

When asked on IRC about this kind of inquiry of a component of an unallocated
derived type, Tobias Burnus answered immediately that such a use is invalid,
pointing to

2.4.9 Allocatable variables
...
2 An unallocated allocatable variable shall not be referenced or defi\fned.
...

Then he made the comment that (obviously) this restriction does not apply for

13.7.11 ALLOCATED (ARRAY) or ALLOCATED (SCALAR)
1 Description. Query allocation status.
2 Class. Inquiry function.
3 Arguments.
   ARRAY shall be an allocatable array.
  SCALAR shall be an allocatable scalar.
4 Result Characteristics. Default logical scalar.
5 Result Value. The result has the value true if the argument (ARRAY or SCALAR)
is allocated and has the
value false if the argument is unallocated.

but that 'a(1)%i' is not an array but an invalid expression per 2.4.9 that
cannot be a valid argument of allocated. Note that my original problem came
from scalar allocatable and that the above was less obvious for 'a%i'.

It would be nice to have a run time check for such invalid use of unallocated
allocatable variables (such as -fcheck=use_unalloc).


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-10-26 14:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-26 12:17 [Bug libfortran/46182] New: Run time check for invalid use of unallocated allocatable variables dominiq at lps dot ens.fr
2010-10-26 13:18 ` Mikael Morin
2010-10-26 14:07 ` [Bug libfortran/46182] " dominiq at lps dot ens.fr
2010-10-26 14:29 ` mikael at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).