comp.lang.ada
 help / color / mirror / Atom feed
* Repost: Nobody interested to judge which compiler is right?!
@ 2003-01-29 23:00 Wojtek Narczynski
  2003-01-30  0:13 ` tmoran
  0 siblings, 1 reply; 6+ messages in thread
From: Wojtek Narczynski @ 2003-01-29 23:00 UTC (permalink / raw)


Hello,

Please excuse me the disruption, but I believe this problem is
interesting.

The code below compiles with GNAT, but not with Aonix. Could you
people try with other compilers?

Something tells me that if the code is correct, then an Ada compiler
(practically) must support fat pointers. That's the interesting part.


The RM sections IMHO relevant:

3.10.2 27/1 "if D is untagged, then the type of the view shall be D,
and A's designated subtype shall (...) statically match the nominal
subtype of the view or (...)"

4.9.1 2 " A subtype statically matches another subtype of the same
type if they have statically matching constraints."


Regards,
Wojtek Narczynski


with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Text_IO; use Ada.Text_IO;

procedure Tiny is
-- Is this code valid ?!

	type String_Access is access all String;

	subtype Len_Positive is Positive range 1 .. 20;
	subtype Len_String is String ( Len_Positive );
	subtype Len_String_Access is String_Access( Len_Positive );

	LS : aliased Len_String := Len_String'Length * "*";


	-- \/ This compiles with GNAT, but not with Aonix
	LSA : Len_String_Access := LS'access;


begin

	-- \/ This compiles with GNAT, but not with Aonix
	Put_Line( LSA.all );

end Tiny;



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

* Re: Repost: Nobody interested to judge which compiler is right?!
  2003-01-29 23:00 Wojtek Narczynski
@ 2003-01-30  0:13 ` tmoran
  0 siblings, 0 replies; 6+ messages in thread
From: tmoran @ 2003-01-30  0:13 UTC (permalink / raw)


>       -- \/ This compiles with GNAT, but not with Aonix
>       LSA : Len_String_Access := LS'access;
  Janus 3.1.2 gives
   17:          LSA : Len_String_Access := LS'access;
-------------------------------------------^
*ERROR* Object fails subtype conformance check (6.4.19) [RM 3.10.2(27)]
  and the Janus manual 6.4.19 says
"The object must have constraints which statically match with the access
type's designated type's constraints."



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

* Re: Repost: Nobody interested to judge which compiler is right?!
@ 2003-01-30  6:53 Grein, Christoph
  2003-01-30 18:52 ` Wojtek Narczynski
  0 siblings, 1 reply; 6+ messages in thread
From: Grein, Christoph @ 2003-01-30  6:53 UTC (permalink / raw)
  To: comp.lang.ada

Well I'm no language lawyer, but in my opinion, Gnat is wrong and Aonix is 
right.

> with Ada.Strings.Fixed; use Ada.Strings.Fixed;
> with Ada.Text_IO; use Ada.Text_IO;
> 
> procedure Tiny is
> -- Is this code valid ?!
> 
> 	type String_Access is access all String;
> 
> 	subtype Len_Positive is Positive range 1 .. 20;
> 	subtype Len_String is String ( Len_Positive );
> 	subtype Len_String_Access is String_Access( Len_Positive );
> 
> 	LS : aliased Len_String := Len_String'Length * "*";
> 
> 
> 	-- \/ This compiles with GNAT, but not with Aonix
> 	LSA : Len_String_Access := LS'access;
> 
> 
> begin
> 
> 	-- \/ This compiles with GNAT, but not with Aonix
> 	Put_Line( LSA.all );
> 
> end Tiny;

LS nominal and actual subtypes are the same: Len_String

The designated subtype of String_Access and Len_String_Access both are String, 
i.e. an unconstrainted subtype. This is from a note of Tucker Taft on Team Ada 
March 1999. I have no longer the exact English wording, I retranslate from 
German:

"The designated subtype is determined by the declaration of an access type, it 
is the same for all subtypes of that access type, even when the access subtypes 
pose some constraints on the designated subtype."

You could try

  LS : aliased String := Len_String'Length * "*";

Now the nominal subtype of LS is String, the actual subtype is Len_String, i.e. 
LS is constrained by its initial value. Now the subtypes match and

  LSA : Len_String_Access := LS'access;

should be OK. (Warning: I haven't compiled this.)



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

* Re: Repost: Nobody interested to judge which compiler is right?!
  2003-01-30  6:53 Grein, Christoph
@ 2003-01-30 18:52 ` Wojtek Narczynski
  2003-01-30 20:19   ` Robert A Duff
  0 siblings, 1 reply; 6+ messages in thread
From: Wojtek Narczynski @ 2003-01-30 18:52 UTC (permalink / raw)


> This is from a note of Tucker Taft on Team Ada March 1999.
> I have no longer the exact English wording, I retranslate from 
> (...)

I found it:

http://www.acm.org/archives/wa.cgi?A2=ind9903&L=team-ada&F=&S=&P=10682

I even think I understand it. The purpose of an index_constraint on an
unconstrained access to array type is to introduce a runtime range
check, that's all. Unfortunately...

-- This slightly modified code raises Constraint_Error as expected. 

    type String_Access is access all String;
    
    subtype Len_Positive is Positive range 1 .. 20;
    subtype Len_String is String ( Len_Positive );
    subtype Len_String_Access is String_Access( Len_Positive );

    -- Ada 95 version, no GNAT version
    -- Create a string too long
    LS : aliased String := 2 * Len_String'Length * "*";
   		    
    -- Raises Constraint_Error
    LSA : Len_String_Access := LS'access;

Now that I know that GNAT is not compliant, do you think I should
report it?

Thanks & Regards,
Wojtek



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

* Re: Repost: Nobody interested to judge which compiler is right?!
  2003-01-30 18:52 ` Wojtek Narczynski
@ 2003-01-30 20:19   ` Robert A Duff
  0 siblings, 0 replies; 6+ messages in thread
From: Robert A Duff @ 2003-01-30 20:19 UTC (permalink / raw)


wojtek@power.com.pl (Wojtek Narczynski) writes:

> Now that I know that GNAT is not compliant, do you think I should
> report it?

Yes!

I haven't completely followed this thread, but surely it's a good thing
for the Ada community if all Ada compilers agree on what's legal and
what isn't.

- Bob




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

* Re: Repost: Nobody interested to judge which compiler is right?!
@ 2003-01-31  6:25 Grein, Christoph
  0 siblings, 0 replies; 6+ messages in thread
From: Grein, Christoph @ 2003-01-31  6:25 UTC (permalink / raw)
  To: comp.lang.ada

> Now that I know that GNAT is not compliant, do you think I should
> report it?

Perhaps, but I have by coincidence just also come across the feature, so I'm going to report it as a 
supported customer. This will get higher priority.



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

end of thread, other threads:[~2003-01-31  6:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-31  6:25 Repost: Nobody interested to judge which compiler is right?! Grein, Christoph
  -- strict thread matches above, loose matches on Subject: below --
2003-01-30  6:53 Grein, Christoph
2003-01-30 18:52 ` Wojtek Narczynski
2003-01-30 20:19   ` Robert A Duff
2003-01-29 23:00 Wojtek Narczynski
2003-01-30  0:13 ` tmoran

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox