From: Jere <jhb.chat@gmail.com>
Subject: Possible GNAT bug, but wanted to see if it was a violtion of the RM
Date: Thu, 22 Feb 2018 18:36:29 -0800 (PST)
Date: 2018-02-22T18:36:29-08:00 [thread overview]
Message-ID: <906cd418-adff-4eeb-9da5-7c6f7c777ff8@googlegroups.com> (raw)
It took a while, but I got a small contrived example to get this bug.
The gist:
Windows 10
GNAT GPL 2017
FSF GNAT 7.2 hosted on mingw64 for x86_64
I was working on some code that used composition to build up some
components. I was adding iteration to the top level component using
an internal component as the basis for it. I started running into
runtime error when I did a "for E of Container loop" construct. The
exceptions happened at the end of the program and raised Program_Error
mentioning an exception in Finalize/Adjust. Below is a very contrived
example, but I wanted a minimal compilable example to provide.
I'm certain there is a GNAT bug here, as merely changing how I call a
function (changing from object.function to package.function(object)),
removes the runtime error. On the flip side, I am using anonymous
access types (as required for the indexing operations), so I might
be misusing those accidentally. My question is if this is legal
code (and a bug) or not. I don't know anonymous access types well
enough to know for sure.
**********************************************************************
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Vectors;
procedure Main is
package Composite is
package Vectors is new Ada.Containers.Vectors(Positive,Integer);
type Instance is tagged limited record
Vector : Vectors.Vector;
end record
with
Default_Iterator => Iterate,
Constant_Indexing => Constant_Reference,
Iterator_Element => Integer;
type Constant_Reference_Type
(Element : not null access constant Integer)
is limited null record
with Implicit_Dereference => Element;
function Constant_Reference
(Container : aliased Instance;
Cursor : Vectors.Cursor)
return Constant_Reference_Type
-- This version causes a runtime error:
-- raised PROGRAM_ERROR : main.adb:4 finalize/adjust raised exception
is (Element =>
Container.Vector.Constant_Reference(Cursor).Element);
-- -- This version works and does not causes a runtime error
-- is (Element =>
-- Vectors.Constant_Reference(Container.Vector,Cursor).Element);
function Iterate
(Container : Instance)
return Vectors.Vector_Iterator_Interfaces.Reversible_Iterator'Class
is (Container.Vector.Iterate);
end Composite;
Container : Composite.Instance;
begin
for I in 1..5 loop
Container.Vector.Append(I);
end loop;
for E of Container loop
Put_Line(Integer'Image(E));
end loop;
end Main;
**********************************************************************
Output:
main.exe
1
2
3
4
5
raised PROGRAM_ERROR : main.adb:4 finalize/adjust raised exception
[2018-02-22 21:25:48] process exited with status 1, elapsed time: 00.20s
next reply other threads:[~2018-02-23 2:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-23 2:36 Jere [this message]
2018-02-23 9:16 ` Possible GNAT bug, but wanted to see if it was a violtion of the RM Simon Wright
2018-02-24 22:07 ` Jere
2018-02-25 11:55 ` Simon Wright
2018-02-25 15:55 ` Jere
2018-02-24 22:10 ` Jere
2018-02-25 11:50 ` Simon Wright
2018-02-25 15:22 ` Jere
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox