* [Ada] Better error message for illegal use of 'Access in a call.
@ 2017-04-25 8:47 Arnaud Charlet
0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2017-04-25 8:47 UTC (permalink / raw)
To: gcc-patches; +Cc: Ed Schonberg
[-- Attachment #1: Type: text/plain, Size: 1283 bytes --]
This patch improves the error message in the case of an attribute reference
that is an actual in a call to a subprogram inherited from a generic formal
type with unknown discriminants, which makes the subprogram and its formal
parameters intrinsic (see RM 6.3.1 (8) and (13)).
Compiling l.adb must yield:
l.adb:6:08: subprogram and its formal paramenters have convention Intrinsic
l.adb:6:22: actual cannot be access attribute
with G;
generic
type D (<>) is new G.T with private;
package L is
type DT is new D with null record;
procedure Foo (A_T : DT; P : access procedure);
end;
---
package body L is
procedure Foo (A_T : DT; P : access procedure) is
procedure Q is begin null; end;
begin
D (A_T).Foo (Q'Access);
end Foo;
end;
---
package G is
type T is tagged null record;
procedure Foo (A_T : T; P : access procedure);
end;
Tested on x86_64-pc-linux-gnu, committed on trunk
2017-04-25 Ed Schonberg <schonberg@adacore.com>
* sem_attr.adb (Analyze_Attribute, case 'Access): Specialize
the error message when the attribute reference is an actual in
a call to a subprogram inherited from a generic formal type with
unknown discriminants, which makes the subprogram and its formal
parameters intrinsic (see RM 6.3.1 (8) and (13)).
[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 2057 bytes --]
Index: sem_attr.adb
===================================================================
--- sem_attr.adb (revision 247147)
+++ sem_attr.adb (working copy)
@@ -10532,11 +10532,34 @@
if Convention (Designated_Type (Btyp)) /=
Convention (Entity (P))
then
- Error_Msg_FE
- ("subprogram & has wrong convention", P, Entity (P));
- Error_Msg_Sloc := Sloc (Btyp);
- Error_Msg_FE ("\does not match & declared#", P, Btyp);
+ -- The rule in 6.3.1 (8) deserves a special error
+ -- message.
+ if Convention (Btyp) = Convention_Intrinsic
+ and then Nkind (Parent (N)) = N_Procedure_Call_Statement
+ and then Is_Entity_Name (Name (Parent (N)))
+ and then Inside_A_Generic
+ then
+ declare
+ Subp : constant Entity_Id :=
+ Entity (Name (Parent (N)));
+ begin
+ if Convention (Subp) = Convention_Intrinsic then
+ Error_Msg_FE ("subprogram and its formal "
+ & "parameters have convention Intrinsic",
+ Parent (N), Subp);
+ Error_Msg_N
+ ("actual cannot be access attribute", N);
+ end if;
+ end;
+
+ else
+ Error_Msg_FE
+ ("subprogram & has wrong convention", P, Entity (P));
+ Error_Msg_Sloc := Sloc (Btyp);
+ Error_Msg_FE ("\does not match & declared#", P, Btyp);
+ end if;
+
if not Is_Itype (Btyp)
and then not Has_Convention_Pragma (Btyp)
then
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-04-25 8:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-25 8:47 [Ada] Better error message for illegal use of 'Access in a call Arnaud Charlet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).