Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.lang.ada > #49806

Re: Is this legal?

Newsgroups comp.lang.ada
Date 2021-10-17 01:41 -0700
References <6c49980a-fe55-4cea-a356-d021b417d942n@googlegroups.com>
Message-ID <54181867-ea8d-4fdf-8a5c-dcd167421e79n@googlegroups.com> (permalink)
Subject Re: Is this legal?
From AdaMagica <christ-usch.grein@t-online.de>

Show all headers | View raw


> procedure Main is 
> 
> subtype str5 is string(1..5); 
> type s5_ptr is access all str5; 

Ptr: s5_ptr;

> type T is 
> record 
> --current : access str5; 
> current : s5_ptr; -- "aliased actual has wrong accessibility" 
> foo : aliased str5; 
> end record; 

The accessibility rules are far too complicated and unreadable (I'm not about trying to grock them), but the component current has a type that has a lifetime as long as Main. Your object o may be declared in an inner scope with less lifetime. Thus the assignment must be illegal.

begin
  declare
    o : T := (Acurrent => null, --Ncurrent => null,
             foo => "Hello");
  begin
    P (o);
    --Ptr := o.Ncurrent;  -- global point to disappearing object
    Ptr := o.Acurrent;  -- global point to disappearing object
  end;
  put_line(Ptr.all);  -- prints Hello
end Main;

But it occurs to me that GNAT CE 2021 has a problem here. (Comment out all occurrences of Ncurrent.)

Back to comp.lang.ada | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Is this legal? Simon Belmont <sbelmont700@gmail.com> - 2021-10-16 12:00 -0700
  Re: Is this legal? Gautier write-only address <gautier_niouzes@hotmail.com> - 2021-10-17 01:35 -0700
  Re: Is this legal? AdaMagica <christ-usch.grein@t-online.de> - 2021-10-17 01:41 -0700
    Re: Is this legal? Simon Belmont <sbelmont700@gmail.com> - 2021-10-17 11:31 -0700
      Re: Is this legal? AdaMagica <christ-usch.grein@t-online.de> - 2021-10-18 03:50 -0700
  Re: Is this legal? "Randy Brukardt" <randy@rrsoftware.com> - 2021-10-18 22:50 -0500

csiph-web