public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-6018] [Ada] Incorrect accessibility level on type in formal package
@ 2020-12-14 15:54 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2020-12-14 15:54 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:7e7d99bfa23c7d84ba48b9131e2134cf4049d791
commit r11-6018-g7e7d99bfa23c7d84ba48b9131e2134cf4049d791
Author: Justin Squirek <squirek@adacore.com>
Date: Fri Nov 20 08:11:12 2020 -0500
[Ada] Incorrect accessibility level on type in formal package
gcc/ada/
* sem_util.adb, sem_util.ads (In_Generic_Formal_Package):
Created to identify type declarations occurring within generic
formal packages.
* sem_res.adb (Resolve_Allocator): Add condition to avoid
emitting an error for allocators when the type being allocated
is class-wide and from a generic formal package.
Diff:
---
gcc/ada/sem_res.adb | 7 +++++--
gcc/ada/sem_util.adb | 22 ++++++++++++++++++++++
gcc/ada/sem_util.ads | 3 +++
3 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index 659db865f93..05ebf20ca26 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -5451,9 +5451,12 @@ package body Sem_Res is
-- Do not apply Ada 2005 accessibility checks on a class-wide
-- allocator if the type given in the allocator is a formal
- -- type. A run-time check will be performed in the instance.
+ -- type or within a formal package. A run-time check will be
+ -- performed in the instance.
- elsif not Is_Generic_Type (Exp_Typ) then
+ elsif not Is_Generic_Type (Exp_Typ)
+ and then not In_Generic_Formal_Package (Exp_Typ)
+ then
Error_Msg_N
("type in allocator has deeper level than designated "
& "class-wide type", E);
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 72dbc6868af..30d4457ea31 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -13827,6 +13827,28 @@ package body Sem_Util is
and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
end In_Assertion_Expression_Pragma;
+ -------------------------------
+ -- In_Generic_Formal_Package --
+ -------------------------------
+
+ function In_Generic_Formal_Package (E : Entity_Id) return Boolean is
+ Par : Node_Id;
+
+ begin
+ Par := Parent (E);
+ while Present (Par) loop
+ if Nkind (Par) = N_Formal_Package_Declaration
+ or else Nkind (Original_Node (Par)) = N_Formal_Package_Declaration
+ then
+ return True;
+ end if;
+
+ Par := Parent (Par);
+ end loop;
+
+ return False;
+ end In_Generic_Formal_Package;
+
----------------------
-- In_Generic_Scope --
----------------------
diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
index b2af43a7406..2e913594bc0 100644
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -1538,6 +1538,9 @@ package Sem_Util is
-- Returns True if node N appears within a pragma that acts as an assertion
-- expression. See Sem_Prag for the list of qualifying pragmas.
+ function In_Generic_Formal_Package (E : Entity_Id) return Boolean;
+ -- Returns True if entity E is inside a generic formal package
+
function In_Generic_Scope (E : Entity_Id) return Boolean;
-- Returns True if entity E is inside a generic scope
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-12-14 15:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-14 15:54 [gcc r11-6018] [Ada] Incorrect accessibility level on type in formal package Pierre-Marie de Rodat
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).