The compiler rejects a declare expression whose declarations are only
object renaming declarations, when the expression references those
local objects.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* sem_res.adb (Resolve_Declare_Expression): Retrieve the created
block entity that is the scope of the local declarations, from
either a local object declaration or an object renaming
declaration. The block entity does not have an explicit
declaration, but appears as the scope of all locally declared
objects.
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -7441,11 +7441,14 @@ package body Sem_Res is
-- Install the scope created for local declarations, if
-- any. The syntax allows a Declare_Expression with no
-- declarations, in analogy with block statements.
+ -- Note that that scope has no explicit declaration, but
+ -- appears as the scope of all entities declared therein.
Decl := First (Actions (N));
while Present (Decl) loop
- exit when Nkind (Decl) = N_Object_Declaration;
+ exit when Nkind (Decl)
+ in N_Object_Declaration | N_Object_Renaming_Declaration;
Next (Decl);
end loop;