comp.lang.ada
 help / color / mirror / Atom feed
* Bug in GNAT?
@ 2002-11-09  6:56 Victor Porton
  2002-11-09  9:43 ` Michal Nowak
  2002-11-09 10:01 ` Victor Porton
  0 siblings, 2 replies; 6+ messages in thread
From: Victor Porton @ 2002-11-09  6:56 UTC (permalink / raw)


GNAT-3.14p compiles the following without error-messages.
Is it a bug in GNAT or in Ada Standard?

function F(A: Integer) return Integer is begin return 1; end;
Y: Integer renames F(3);

Seemingly GNAT parser "thinks" that F(3) is an array element
:-)



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

* Re: Bug in GNAT?
  2002-11-09  6:56 Bug in GNAT? Victor Porton
@ 2002-11-09  9:43 ` Michal Nowak
  2002-11-09 10:01 ` Victor Porton
  1 sibling, 0 replies; 6+ messages in thread
From: Michal Nowak @ 2002-11-09  9:43 UTC (permalink / raw)




On 2002-11-09 at 11:56 porton@ex-code.com wrote:

>GNAT-3.14p compiles the following without error-messages.
>Is it a bug in GNAT or in Ada Standard?

Neither one.

>function F(A: Integer) return Integer is begin return 1; end;
>Y: Integer renames F(3);
>
>Seemingly GNAT parser "thinks" that F(3) is an array element
>:-)

No, it thinks it is renaming an object.
See Reference Manual, 8.5.1 Object Renaming Declarations:

1	An object_renaming_declaration is used to rename an object.

Legality Rules
4	The renamed entity shall be an object.

The function F is returning an object of type Integer. 
So, if you invoke F(3) you get an object in result and then
you rename it to Y. 
Feeling beteer? :-)

Michal


-- -----------------------------------------------------------------
--   ___        _
--  / _ \      | |                      I Choose Ada:
-- | |_| |  ___| |   _____   The Most Trusted Name in Software (TM)
-- |  _  | | __  |  | __  | 
-- |_| |_| |_____|_ |_____|_ http://www.adaic.org/whyada/choose.html
--
-- -----------------------------------------------------------------




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

* Re: Bug in GNAT?
  2002-11-09  6:56 Bug in GNAT? Victor Porton
  2002-11-09  9:43 ` Michal Nowak
@ 2002-11-09 10:01 ` Victor Porton
  2002-11-09 12:26   ` Michal Nowak
                     ` (2 more replies)
  1 sibling, 3 replies; 6+ messages in thread
From: Victor Porton @ 2002-11-09 10:01 UTC (permalink / raw)


In article <mailman.1036834503.25329.comp.lang.ada@ada.eu.org>,
	Michal Nowak <vinnie@inetia.pl> writes:
> 
> On 2002-11-09 at 11:56 porton@ex-code.com wrote:
> 
>>GNAT-3.14p compiles the following without error-messages.
>>Is it a bug in GNAT or in Ada Standard?
> 
> Neither one.
> 
>>function F(A: Integer) return Integer is begin return 1; end;
>>Y: Integer renames F(3);
>>
>>Seemingly GNAT parser "thinks" that F(3) is an array element
>>:-)
> 
> No, it thinks it is renaming an object.
> See Reference Manual, 8.5.1 Object Renaming Declarations:
> 
> 1	An object_renaming_declaration is used to rename an object.
> 
> Legality Rules
> 4	The renamed entity shall be an object.
> 
> The function F is returning an object of type Integer. 
> So, if you invoke F(3) you get an object in result and then
> you rename it to Y. 
> Feeling beteer? :-)

But this compiles with an error:

function F(A: Integer) return Integer is begin return 1; end;
Y: Integer renames F(3)+2;

What is the difference?



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

* Re: Bug in GNAT?
  2002-11-09 10:01 ` Victor Porton
@ 2002-11-09 12:26   ` Michal Nowak
  2002-11-09 15:26   ` David C. Hoos, Sr.
  2002-11-09 15:31   ` Robert A Duff
  2 siblings, 0 replies; 6+ messages in thread
From: Michal Nowak @ 2002-11-09 12:26 UTC (permalink / raw)


On 2002-11-09 at 15:01 porton@ex-code.com wrote:

[snip]
>> The function F is returning an object of type Integer. 
>> So, if you invoke F(3) you get an object in result and then
>> you rename it to Y. 
>> Feeling beteer? :-)
>
>But this compiles with an error:
>
>function F(A: Integer) return Integer is begin return 1; end;
>Y: Integer renames F(3)+2;
>
>What is the difference?

I'm not an Ada guru yet, but I think that what you written above
is a renaming of a compound expression ( F(3)+2 ) and there is
no such feature in Ada. As I am not sure if my expalantion is 
right this time, I hope we get answer from somebody who is better
is this subject.

Michal


-- -----------------------------------------------------------------
--   ___        _
--  / _ \      | |                      I Choose Ada:
-- | |_| |  ___| |   _____   The Most Trusted Name in Software (TM)
-- |  _  | | __  |  | __  | 
-- |_| |_| |_____|_ |_____|_ http://www.adaic.org/whyada/choose.html
--
-- -----------------------------------------------------------------




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

* Re: Bug in GNAT?
  2002-11-09 10:01 ` Victor Porton
  2002-11-09 12:26   ` Michal Nowak
@ 2002-11-09 15:26   ` David C. Hoos, Sr.
  2002-11-09 15:31   ` Robert A Duff
  2 siblings, 0 replies; 6+ messages in thread
From: David C. Hoos, Sr. @ 2002-11-09 15:26 UTC (permalink / raw)



----- Original Message ----- 
From: "Victor Porton" <porton@ex-code.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: November 09, 2002 4:01 AM
Subject: Re: Bug in GNAT?


> In article <mailman.1036834503.25329.comp.lang.ada@ada.eu.org>,
> Michal Nowak <vinnie@inetia.pl> writes:
> > 
> > On 2002-11-09 at 11:56 porton@ex-code.com wrote:
> > 
> >>GNAT-3.14p compiles the following without error-messages.
> >>Is it a bug in GNAT or in Ada Standard?
> > 
> > Neither one.
> > 
> >>function F(A: Integer) return Integer is begin return 1; end;
> >>Y: Integer renames F(3);
> >>
> >>Seemingly GNAT parser "thinks" that F(3) is an array element
> >>:-)
> > 
> > No, it thinks it is renaming an object.
> > See Reference Manual, 8.5.1 Object Renaming Declarations:
> > 
> > 1 An object_renaming_declaration is used to rename an object.
> > 
> > Legality Rules
> > 4 The renamed entity shall be an object.
> > 
> > The function F is returning an object of type Integer. 
> > So, if you invoke F(3) you get an object in result and then
> > you rename it to Y. 
> > Feeling beteer? :-)
> 
> But this compiles with an error:
> 
> function F(A: Integer) return Integer is begin return 1; end;
> Y: Integer renames F(3)+2;
Renaming declarations (according to the Ada Reference Manual)
can only rename a _name_.  Thus, since F(3)+2 is not a name,
but F(3) is a name, the behavior you are observing is legal.

Read the syntax definitions for Renaming_Declarations in
8.5 through 8.5.6, and the definition of Name in 4.1

> 
> What is the difference?
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
> 




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

* Re: Bug in GNAT?
  2002-11-09 10:01 ` Victor Porton
  2002-11-09 12:26   ` Michal Nowak
  2002-11-09 15:26   ` David C. Hoos, Sr.
@ 2002-11-09 15:31   ` Robert A Duff
  2 siblings, 0 replies; 6+ messages in thread
From: Robert A Duff @ 2002-11-09 15:31 UTC (permalink / raw)


porton@ex-code.com (Victor Porton) writes:

> But this compiles with an error:
> 
> function F(A: Integer) return Integer is begin return 1; end;
> Y: Integer renames F(3)+2;
> 
> What is the difference?

Look at the syntax rules.  Renaming requires a "name".  A function_call
is a name, but that thing with "+" in the middle is an "expression",
and not a name.

6.6 says operator notation is equivalent to function call notation,
but that only applies to the semantics -- as this example shows, they
are *not* equivalent syntactically.

    Y: Integer renames "+"(F(3), 2); -- OK
    Y: Integer renames F(3) + 2; -- illegal

I happen to think this is a bug in the language design -- there should
be no syntactic distinction between names and expressions.  And no
distinction between "constant object" and "value".

By the way, the ability to rename function results did not exist in Ada 83.

- Bob



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

end of thread, other threads:[~2002-11-09 15:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-09  6:56 Bug in GNAT? Victor Porton
2002-11-09  9:43 ` Michal Nowak
2002-11-09 10:01 ` Victor Porton
2002-11-09 12:26   ` Michal Nowak
2002-11-09 15:26   ` David C. Hoos, Sr.
2002-11-09 15:31   ` Robert A Duff

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