* "Ada Gems": Constructor functions
@ 2007-09-05 18:10 Tomek Wałkuski
2007-09-05 22:47 ` Jeffrey R. Carter
` (2 more replies)
0 siblings, 3 replies; 15+ messages in thread
From: Tomek Wałkuski @ 2007-09-05 18:10 UTC (permalink / raw)
Hi,
motivated by this article posted at adacore.com I have written some
code:
---------
t.ads
---------
with Ada.Strings.Unbounded;
use Ada.Strings.Unbounded;
package T is
type Object (<>) is tagged limited private;
function Create_Object (Name : in String) return Object;
function Construct return Object;
function Name (This : in Object) return String;
type Object is tagged limited
record
Name : Unbounded_String;
end record;
end T;
---------
t.adb
---------
package body T is
function Create_Object (Name : in String) return Object is
return (Name => To_Unbounded_String (Name));
end Create_Object;
function Construct return Object is
return Create_Object (Name => "Object without a name!");
end Construct;
function Name (This : in Object) return String is
begin
return To_String (This.Name);
end Name;
type Object is tagged limited
record
Name : Unbounded_String;
end record;
end T;
---------
test_t.adb
---------
with T;
procedure Test_T is
Some_Object : constant T.Object := Construct;
begin
null;
end Test_T;
------------------------------
... and tried to compile it.
(Gentoo Linux, gnat-gpl-4.1.3.2007)
Compiler said:
"
+================GNAT BUG DETECTED==================+
| GPL 2007 (20070402-41) (i686-pc-linux-gnu) Assert_Failure namet.adb:
687 |
(...)
compilation abandoned
gnatmake: "test_t.adb" compilation error
"
Is it REALLY a compiler bug? Or am I only dumb? :) Maybe I'm doing
something, somewhere wrong?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: "Ada Gems": Constructor functions
2007-09-05 18:10 "Ada Gems": Constructor functions Tomek Wałkuski
@ 2007-09-05 22:47 ` Jeffrey R. Carter
[not found] ` <1189064716.528979.201170@19g2000hsx.googlegroups.com>
2007-09-06 0:04 ` Robert A Duff
2007-09-06 16:16 ` anon
2 siblings, 1 reply; 15+ messages in thread
From: Jeffrey R. Carter @ 2007-09-05 22:47 UTC (permalink / raw)
Tomek Wa�kuski wrote:
>
> with Ada.Strings.Unbounded;
> use Ada.Strings.Unbounded;
>
> package T is
> type Object (<>) is tagged limited private;
>
> function Create_Object (Name : in String) return Object;
> function Construct return Object;
> function Name (This : in Object) return String;
>
> type Object is tagged limited
> record
> Name : Unbounded_String;
> end record;
> end T;
T has a private type (Object) but no private part.
> package body T is
> function Create_Object (Name : in String) return Object is
> return (Name => To_Unbounded_String (Name));
> end Create_Object;
>
> function Construct return Object is
> return Create_Object (Name => "Object without a name!");
> end Construct;
>
> function Name (This : in Object) return String is
> begin
> return To_String (This.Name);
> end Name;
>
> type Object is tagged limited
> record
> Name : Unbounded_String;
> end record;
> end T;
Type Object is repeated here.
> with T;
>
> procedure Test_T is
> Some_Object : constant T.Object := Construct;
> begin
> null;
> end Test_T;
Construct is not directly visible here.
> Is it REALLY a compiler bug? Or am I only dumb? :) Maybe I'm doing
> something, somewhere wrong?
It's really a compiler error. A compiler should be able to handle the
errors in your code without crashing.
FWIW, I got this with another version:
gnatmake -O2 -gnaton -fstack-check test_t.adb
gcc -c -O2 -gnaton -fstack-check test_t.adb
test_t.adb:4:39: "Construct" is not visible
test_t.adb:4:39: non-visible declaration at t.ads:8
t.ads:11:04: declaration of full view must appear in private part
gnatmake: "test_t.adb" compilation error
--
Jeff Carter
"Death awaits you all, with nasty, big, pointy teeth!"
Monty Python & the Holy Grail
20
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: "Ada Gems": Constructor functions
2007-09-05 18:10 "Ada Gems": Constructor functions Tomek Wałkuski
2007-09-05 22:47 ` Jeffrey R. Carter
@ 2007-09-06 0:04 ` Robert A Duff
2007-09-06 16:16 ` anon
2 siblings, 0 replies; 15+ messages in thread
From: Robert A Duff @ 2007-09-06 0:04 UTC (permalink / raw)
Tomek Wa�kuski <tomek.walkuski@gmail.com> writes:
> Is it REALLY a compiler bug? Or am I only dumb? :) Maybe I'm doing
> something, somewhere wrong?
Well, there are several mistakes in the code you posted. Jeff mentioned
some. Also, there are a couple of missing "begin"s in function bodies.
But "GNAT BUG DETECTED" really means what it says -- if you make a
mistake, the compiler should tell you about it, rather than crashing
with the bug-box message. So yes, this is a compiler bug, by
definition.
Are you sure the code you posted is identical to the code that caused
the bug box?
- Bob
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: "Ada Gems": Constructor functions
[not found] ` <1189064716.528979.201170@19g2000hsx.googlegroups.com>
@ 2007-09-06 7:54 ` Tomek Wa kuski
2007-09-06 13:55 ` Robert A Duff
0 siblings, 1 reply; 15+ messages in thread
From: Tomek Wa kuski @ 2007-09-06 7:54 UTC (permalink / raw)
The "working" code is:
t.ads:
with Ada.Strings.Unbounded;
use Ada.Strings.Unbounded;
package T is
type Object (<>) is tagged limited private;
function Create_Object (Name : in String) return Object;
function Construct return Object;
function Name (This : in Object) return String;
private
type Object is tagged limited
record
Name : Unbounded_String;
end record;
end T;
t.adb:
package body T is
function Create_Object (Name : in String) return Object is
begin
return (Name => To_Unbounded_String (Name));
end Create_Object;
function Construct return Object is
begin
return Create_Object (Name => "Object without a name!");
end Construct;
function Name (This : in Object) return String is
begin
return To_String (This.Name);
end Name;
end T;
test_t.adb:
with T;
procedure Test_T is
Some_Object : constant T.Object := Construct;
begin
null;
end Test_T;
------
tomek@genbox [~/Desktop/test_t] $ gnatmake test_t.adb
gnatgcc -c test_t.adb
test_t.adb:4:39: "Construct" is not visible
test_t.adb:4:39: non-visible declaration at t.ads:8
gnatmake: "test_t.adb" compilation error
(and no bug report)
Why "Construct" is not visible?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: "Ada Gems": Constructor functions
2007-09-06 7:54 ` Tomek Wa kuski
@ 2007-09-06 13:55 ` Robert A Duff
2007-09-06 14:12 ` Tomek Wa kuski
0 siblings, 1 reply; 15+ messages in thread
From: Robert A Duff @ 2007-09-06 13:55 UTC (permalink / raw)
Tomek Wa kuski <tomek.walkuski@gmail.com> writes:
> Some_Object : constant T.Object := Construct;
...
> Why "Construct" is not visible?
You need to say T.Construct, just like you said T.Object.
Or else you need a use clause.
- Bob
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: "Ada Gems": Constructor functions
2007-09-06 13:55 ` Robert A Duff
@ 2007-09-06 14:12 ` Tomek Wa kuski
0 siblings, 0 replies; 15+ messages in thread
From: Tomek Wa kuski @ 2007-09-06 14:12 UTC (permalink / raw)
On 6 Wrz, 15:55, Robert A Duff <bobd...@shell01.TheWorld.com> wrote:
> You need to say T.Construct, just like you said T.Object.
> Or else you need a use clause.
I tried this before:
tomek@genbox [~/Desktop/test_t] $ gnatmake test_t.adb
gnatgcc -c test_t.adb
gnatgcc -c t.adb
+===========================GNAT BUG
DETECTED==============================+
| GPL 2007 (20070402-41) (i686-pc-linux-gnu) Assert_Failure namet.adb:
687 |
| Error detected at t.adb:
4:7 |
| Please submit a bug report by email to
report@adacore.com. |
| GAP members can alternatively use GNAT
Tracker: |
| http://www.adacore.com/ section 'send a
report'. |
| See gnatinfo.txt for full info on procedure for submitting
bugs. |
| Use a subject line meaningful to you and us to track the
bug. |
| Include the entire contents of this bug box in the
report. |
| Include the exact gcc or gnatmake command that you
entered. |
| Also include sources listed below in gnatchop
format |
| (concatenated together with no headers between
files). |
| Use plain ASCII or MIME
attachment. |
+==========================================================================
+
Please include these source files with error report
Note that list may not be accurate in some cases,
so please double check that the problem can still
be reproduced with the set of files listed.
t.adb
t.ads
compilation abandoned
gnatmake: "t.adb" compilation error
----
Submit bug report?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: "Ada Gems": Constructor functions
2007-09-05 18:10 "Ada Gems": Constructor functions Tomek Wałkuski
2007-09-05 22:47 ` Jeffrey R. Carter
2007-09-06 0:04 ` Robert A Duff
@ 2007-09-06 16:16 ` anon
2007-09-07 10:38 ` Tomek Wa kuski
2 siblings, 1 reply; 15+ messages in thread
From: anon @ 2007-09-06 16:16 UTC (permalink / raw)
Yes, you did find a GNAT BUG!
To find the line numbers and errors try
gnat1 t.adb -gnatl 2>t.lst
gnat1 test_t.adb -gnatl 2>test_t.lst
But to make a report to Adacore:
First compile using
gnatmake test_t.adb 1>1 2>2
-- Note: File '2' should have the error info that Adacore is
-- asking about.
Then send Adacore the following list of files
attach file => t.ads
attach file => t.adb
attach file => test_t.adb
attach file => 1
-- Note: Send File 1 only if it has any special info else skip
--
attach file => 2
I use Ada 95 to compile and did not receive the BUG ERROR
only a few normal compiling errors.
Now, for a compilable corrected version in GNAT Ada 95.
Did not use GNAT Ada 2005 compiler.
changes to code:
--- removed => denote the line is commented out
--- Added => denote the line is added to source
other comments added for info only
-----------
-- t.ads --
-----------
with Ada.Strings.Unbounded;
use Ada.Strings.Unbounded;
package T is
-- type Object (<>) is tagged limited private; --------- removed
-------- because can not initial
-------- a limited type in Ada 95
type Object (<>) is private; --------- Added
function Create_Object (Name : in String) return Object;
function Construct return Object;
function Name (This : in Object) return String;
private ------------------------------ Added
-- type Object is tagged limited -------- removed
-------- because can not initial
-------- a limited type in Ada 95
type Object is ------------------------ Added
record
Name : Unbounded_String;
end record;
end T;
-----------
-- t.adb --
-----------
package body T is
function Create_Object (Name : in String) return Object is
begin --------- Added
return (Name => To_Unbounded_String (Name));
end Create_Object;
function Construct return Object is
begin --------- Added
return Create_Object (Name => "Object without a name!");
end Construct;
function Name (This : in Object) return String is
begin
return To_String (This.Name);
end Name;
---------------------------------------- removed
-- ----- because it conflicts
-- ----- with t.ads version
-- type Object is tagged limited
-- record
-- Name : Unbounded_String;
-- end record;
end T;
----------------
-- test_t.ads --
----------------
with T;
use T; ------ Added
------ could of added "T." to Construct instead
procedure Test_T is
Some_Object : constant T.Object := Construct;
begin
null;
end Test_T;
In <1189015827.384331.17490@k79g2000hse.googlegroups.com>, =?iso-8859-2?q?Tomek_Wa=B3kuski?= <tomek.walkuski@gmail.com> writes:
>Hi,
>
>motivated by this article posted at adacore.com I have written some
>code:
>
>---------
>t.ads
>---------
>with Ada.Strings.Unbounded;
>use Ada.Strings.Unbounded;
>
>package T is
> type Object (<>) is tagged limited private;
>
> function Create_Object (Name : in String) return Object;
> function Construct return Object;
> function Name (This : in Object) return String;
>
> type Object is tagged limited
> record
> Name : Unbounded_String;
> end record;
>end T;
>
>
>---------
>t.adb
>---------
>package body T is
> function Create_Object (Name : in String) return Object is
> return (Name => To_Unbounded_String (Name));
> end Create_Object;
>
> function Construct return Object is
> return Create_Object (Name => "Object without a name!");
> end Construct;
>
> function Name (This : in Object) return String is
> begin
> return To_String (This.Name);
> end Name;
>
> type Object is tagged limited
> record
> Name : Unbounded_String;
> end record;
>end T;
>
>
>---------
>test_t.adb
>---------
>with T;
>
>procedure Test_T is
> Some_Object : constant T.Object := Construct;
>begin
> null;
>end Test_T;
>
>------------------------------
>.... and tried to compile it.
>
>(Gentoo Linux, gnat-gpl-4.1.3.2007)
>
>Compiler said:
>"
>+================GNAT BUG DETECTED==================+
>| GPL 2007 (20070402-41) (i686-pc-linux-gnu) Assert_Failure namet.adb:
>687 |
>(...)
>compilation abandoned
>gnatmake: "test_t.adb" compilation error
>"
>
>Is it REALLY a compiler bug? Or am I only dumb? :) Maybe I'm doing
>something, somewhere wrong?
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: "Ada Gems": Constructor functions
2007-09-06 16:16 ` anon
@ 2007-09-07 10:38 ` Tomek Wa kuski
2007-09-07 15:17 ` Robert A Duff
0 siblings, 1 reply; 15+ messages in thread
From: Tomek Wa kuski @ 2007-09-07 10:38 UTC (permalink / raw)
Report sent.
So.. It is not possible to use Ada2005 standard features mentioned in
Ada Gems article with GNAT complier?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: "Ada Gems": Constructor functions
2007-09-07 10:38 ` Tomek Wa kuski
@ 2007-09-07 15:17 ` Robert A Duff
2007-09-08 18:20 ` Tomek Wa kuski
0 siblings, 1 reply; 15+ messages in thread
From: Robert A Duff @ 2007-09-07 15:17 UTC (permalink / raw)
Tomek Wa kuski <tomek.walkuski@gmail.com> writes:
> Report sent.
Thanks.
> So.. It is not possible to use Ada2005 standard features mentioned in
> Ada Gems article with GNAT complier?
Apparently not with the version you are using. :-(
It does work with the latest version of GNAT, though.
- Bob
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: "Ada Gems": Constructor functions
2007-09-07 15:17 ` Robert A Duff
@ 2007-09-08 18:20 ` Tomek Wa kuski
2007-09-10 13:46 ` Tomek Wa kuski
0 siblings, 1 reply; 15+ messages in thread
From: Tomek Wa kuski @ 2007-09-08 18:20 UTC (permalink / raw)
Got reply:
"
Dear Tomek, the current version of the compiler reports:
> gnatmake test_t.adb
> gcc -c test_t.adb
> test_t.adb:4:40: cannot initialize entities of limited type
> gnatmake: "test_t.adb" compilation error
which seems expected.
"
Huh?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: "Ada Gems": Constructor functions
2007-09-08 18:20 ` Tomek Wa kuski
@ 2007-09-10 13:46 ` Tomek Wa kuski
2007-09-11 7:51 ` Georg Bauhaus
0 siblings, 1 reply; 15+ messages in thread
From: Tomek Wa kuski @ 2007-09-10 13:46 UTC (permalink / raw)
Also, this same code compiled on Windows with GNAT GPL 2007 throws:
> gnatmake test_t.adb
t.adb:4:07: "" is undefined
t.adb:4:07: actual for "From" must be a variable
gnatmake: "c:\documents and settings\tomek\pulpit\test_t\t.adb"
compilation error
There is GNAT bug on every Gentoo box I have got, on Windows I can't
compile it (with... this same compiler) and AdaCore can't reproduce
this bug...
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: "Ada Gems": Constructor functions
2007-09-10 13:46 ` Tomek Wa kuski
@ 2007-09-11 7:51 ` Georg Bauhaus
2007-09-11 10:26 ` Tomek Wa kuski
2007-09-11 21:33 ` Anh Vo
0 siblings, 2 replies; 15+ messages in thread
From: Georg Bauhaus @ 2007-09-11 7:51 UTC (permalink / raw)
Tomek Wa kuski wrote:
> Also, this same code compiled on Windows with GNAT GPL 2007 throws:
>
>> gnatmake test_t.adb
> t.adb:4:07: "" is undefined
> t.adb:4:07: actual for "From" must be a variable
> gnatmake: "c:\documents and settings\tomek\pulpit\test_t\t.adb"
> compilation error
But no GNAT Bug Box this time?
> There is GNAT bug on every Gentoo box I have got, on Windows I can't
> compile it (with... this same compiler) and AdaCore can't reproduce
> this bug...
>
Did they mention which compiler they have used when trying to
reproduce the bug box?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: "Ada Gems": Constructor functions
2007-09-11 7:51 ` Georg Bauhaus
@ 2007-09-11 10:26 ` Tomek Wa kuski
2007-09-11 21:33 ` Anh Vo
1 sibling, 0 replies; 15+ messages in thread
From: Tomek Wa kuski @ 2007-09-11 10:26 UTC (permalink / raw)
On 11 Wrz, 09:51, Georg Bauhaus <bauhaus.rm.t...@maps.futureapps.de>
wrote:
> But no GNAT Bug Box this time?
>
No.
Someone wrote to me, that he managed to compile this code on Windows
XP with this same compiler...
Weird...
> Did they mention which compiler they have used when trying to
> reproduce the bug box?
>
They have said only "current version of the compiler reports".
My friend, also on Gentoo, can reproduce this bug as well (so I have
contacted with Gentoo devs, maybe it is Gentoo issue).
Tomek
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: "Ada Gems": Constructor functions
2007-09-11 7:51 ` Georg Bauhaus
2007-09-11 10:26 ` Tomek Wa kuski
@ 2007-09-11 21:33 ` Anh Vo
2007-09-12 7:39 ` Tomek Wa kuski
1 sibling, 1 reply; 15+ messages in thread
From: Anh Vo @ 2007-09-11 21:33 UTC (permalink / raw)
On Sep 11, 12:51 am, Georg Bauhaus
<bauhaus.rm.t...@maps.futureapps.de> wrote:
> Tomek Wa kuski wrote:
> > Also, this same code compiled on Windows with GNAT GPL 2007 throws:
>
> >> gnatmake test_t.adb
> > t.adb:4:07: "" is undefined
> > t.adb:4:07: actual for "From" must be a variable
> > gnatmake: "c:\documents and settings\tomek\pulpit\test_t\t.adb"
> > compilation error
>
> But no GNAT Bug Box this time?
I got the same result, no GNAT Bug Box, on Windows using GNAT-2007-
GPL. However, it worked fine on Red Hat with gcc-4.3-20070907
snapshot. One interesting observation, if the return statement is
qualified as shown below, it is compiled on Windows, too.
return Object'(Name => To_Unbounded_String (Name));
AV
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: "Ada Gems": Constructor functions
2007-09-11 21:33 ` Anh Vo
@ 2007-09-12 7:39 ` Tomek Wa kuski
0 siblings, 0 replies; 15+ messages in thread
From: Tomek Wa kuski @ 2007-09-12 7:39 UTC (permalink / raw)
On 11 Wrz, 23:33, Anh Vo <anhvofrc...@gmail.com> wrote:
> One interesting observation, if the return statement is
> qualified as shown below, it is compiled on Windows, too.
>
> return Object'(Name => To_Unbounded_String (Name));
>
This compiles on Windows and also on Gentoo box with gnat-
gpl-4.1.3.2007 (which is in fact GNAT GPL 2007 from AdaCore).
This also works:
return New_Object : Object do
New_Object.Name := To_Unbounded_String (Name);
end return;
Mystery solved? :) So... bug must persist in Ada Gems article :)
Tomek
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2007-09-12 7:39 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-05 18:10 "Ada Gems": Constructor functions Tomek Wałkuski
2007-09-05 22:47 ` Jeffrey R. Carter
[not found] ` <1189064716.528979.201170@19g2000hsx.googlegroups.com>
2007-09-06 7:54 ` Tomek Wa kuski
2007-09-06 13:55 ` Robert A Duff
2007-09-06 14:12 ` Tomek Wa kuski
2007-09-06 0:04 ` Robert A Duff
2007-09-06 16:16 ` anon
2007-09-07 10:38 ` Tomek Wa kuski
2007-09-07 15:17 ` Robert A Duff
2007-09-08 18:20 ` Tomek Wa kuski
2007-09-10 13:46 ` Tomek Wa kuski
2007-09-11 7:51 ` Georg Bauhaus
2007-09-11 10:26 ` Tomek Wa kuski
2007-09-11 21:33 ` Anh Vo
2007-09-12 7:39 ` Tomek Wa kuski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox