comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: pragma Convention questions
Date: Mon, 12 Nov 2007 09:02:50 -0800
Date: 2007-11-12T09:02:50-08:00	[thread overview]
Message-ID: <1194886970.773791.47150@k35g2000prh.googlegroups.com> (raw)
In-Reply-To: <87sl3cd9cw.fsf@willow.rfc1149.net>

On Nov 11, 8:39 am, Samuel Tardieu <s...@rfc1149.net> wrote:
> I have several questions regarding pragma Convention in Ada95 for
> language lawyers.

> 2- pragma Convention, renaming and Intrinsic
>
> Is the following code legal?
>
> package U is
>    type Foo is (Foo1, Foo2);
>    function F return Foo renames Foo1;
>    pragma Convention (Ada, F);
>    type Foo_Access is access function return Foo;
>    X : Foo_Access := F'Access;
> end U;
>
> GNAT rejects X initialization with 'prefix of "Access" attribute
> cannot be intrinsic'. Which means that the pragma Convention failed
> silently. Is it allowed to have it fail without a compilation error?
> Or is the 'Access legal?

I think the Convention pragma should be illegal, although it takes a
bit of interpretation.  13.1(6) says, "If a local_name denotes a local
callable entity, it may do so through a local
subprogram_renaming_declaration (as a way to resolve ambiguity in the
presence of overloading); otherwise, the local_name shall not denote a
renaming_declaration."  This implies that, when you apply a
representation item (including Convention, see B.1(28)) to a renaming
subprogram, the semantics and rules are the same as if you had applied
them to the renamed entity.  Here, since there is no ambiguity, this
means that pragma Convention(Ada,F) should be exactly the same as
pragma Convention(Ada,Foo1), and the first should be illegal if the
second is illegal.  As to whether the language makes this illegal,
it's not 100% clear.  However, 6.3.1 divides subprograms into several
groups and defines the default calling convention for each group.
6.3.1(3) says, "The default calling convention for any subprogram not
listed below is Ada. A pragma Convention, Import, or Export may be
used to override the default calling convention (see B.1)."  Based on
how this section is structured, this could be taken to imply that this
is the *only* group for which the default calling convention can be
overridden.  An enumeration literal is not in this group (since it is
"listed below", 6.3.1(5)), and has a default convention of Intrisic;
based on this interpretation, it would mean that you may not apply a
Convention pragma to the enumeration literal---and therefore you may
not apply it to the function that renames the enumeration literal.

Anyway, that's my opinion on this matter; I could have easily missed
some relevant rule somewhere else.

                              -- Adam




  parent reply	other threads:[~2007-11-12 17:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-11 16:39 pragma Convention questions Samuel Tardieu
2007-11-11 19:14 ` Martin Krischik
2007-11-11 20:57   ` Samuel Tardieu
2007-11-12  8:14     ` Martin Krischik
2007-11-12  8:30       ` Samuel Tardieu
2007-11-12 17:02 ` Adam Beneschan [this message]
2007-11-12 21:54   ` Samuel Tardieu
2007-11-15  5:06 ` Randy Brukardt
2007-11-15  7:55   ` Samuel Tardieu
replies disabled

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