This patch suppresses spurious warnings that may be generated when the prefix
of a with_clause for a child unit denotes the renaming of a parent unit.
Such renamings generate internal with_clauses that are not marked Implicit_With
because they must be properly installed as part of the context, but they are
never redundant with explicit with_clauses.
The following must compile quietly:
gcc -c -gnatwa pkg_b2.adb
---
with Renamed_Pkg_A;
package Pkg_B2
is
procedure Proc_1( Val_1 : in out Renamed_Pkg_A.Type_A );
end Pkg_B2;
---
package Pkg_A
is
type Type_A is ( A1, A2 );
end Pkg_A;
---
with Pkg_A;
package Renamed_Pkg_A renames Pkg_A;
---
package Pkg_A.Child_A
is
type Type_B is ( B1, B2 );
end Pkg_A.Child_A;
---
with Renamed_Pkg_A.Child_A;
package body Pkg_B2
is
use type Renamed_Pkg_A.Child_A.Type_B;
Val_B : Renamed_Pkg_A.Child_A.Type_B := Renamed_Pkg_A.Child_A.Type_B'First;
procedure Proc_1( Val_1 : in out Renamed_Pkg_A.Type_A )
is
begin
if Val_B = Renamed_Pkg_A.Child_A.Type_B'First then
Val_1 := Renamed_Pkg_A.Type_A'Last;
Val_B := Renamed_Pkg_A.Child_A.Type_B'Last;
else
Val_B := Renamed_Pkg_A.Child_A.Type_B'First;
end if;
end Proc_1;
end Pkg_B2;
Tested on x86_64-pc-linux-gnu, committed on trunk
2014-08-01 Ed Schonberg <[email protected]>
* sem_ch10.adb (Analyze_Compilation_Unit): Do not place a
warning on a with_clause created for the renaming of a parent
unit in an explicit with_clause.
Index: sem_ch10.adb
===================================================================
--- sem_ch10.adb (revision 213440)
+++ sem_ch10.adb (working copy)
@@ -242,7 +242,7 @@
-- on the context. Note that in contrast with the handling of private
-- types, the limited view and the non-limited view of a type are treated
-- as separate entities, and no entity exchange needs to take place, which
- -- makes the implementation must simpler than could be feared.
+ -- makes the implementation much simpler than could be feared.
------------------------------
-- Analyze_Compilation_Unit --
@@ -507,11 +507,15 @@
-- Avoid checking implicitly generated with clauses, limited with
-- clauses or withs that have pragma Elaborate or Elaborate_All.
+ -- With_clauses introduced for renamings of parent clauses are not
+ -- marked implicit because they need to be properly installed, but
+ -- they do not come from source and do not require warnings.
if Nkind (Clause) = N_With_Clause
and then not Implicit_With (Clause)
and then not Limited_Present (Clause)
and then not Elaborate_Present (Clause)
+ and then Comes_From_Source (Clause)
then
-- Package body-to-spec check