From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1d27f1e3f05269e X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!k35g2000prh.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: pragma Convention questions Date: Mon, 12 Nov 2007 09:02:50 -0800 Organization: http://groups.google.com Message-ID: <1194886970.773791.47150@k35g2000prh.googlegroups.com> References: <87sl3cd9cw.fsf@willow.rfc1149.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1194886971 23318 127.0.0.1 (12 Nov 2007 17:02:51 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 12 Nov 2007 17:02:51 +0000 (UTC) In-Reply-To: <87sl3cd9cw.fsf@willow.rfc1149.net> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: k35g2000prh.googlegroups.com; posting-host=66.126.103.122; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news1.google.com comp.lang.ada:18321 Date: 2007-11-12T09:02:50-08:00 List-Id: On Nov 11, 8:39 am, Samuel Tardieu 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