Scope of Use Clauses - Can Use Clause Hide a previous use clause?
I have the following code that produces the same effects in two different tools:
package gen_pkg is
generic ( W : natural );
constant CONST : natural := W;
end package gen_pkg;
entity name_clash is
end entity name_clash;
architecture clash of name_clash is
package pkg is new work.gen_pkg generic map( 8 );
use pkg.all;
begin
p: process
package pkg is new work.gen_pkg generic map( 9 );
use pkg.all;
begin
report to_string(CONST);
wait;
end process;
end architecture;
Here a package is declared and used in the architecture. Another package with the same name is declared and used in process p
Two different tools have different behaviors that may both be legal WRT the LRM.
Aldec:
Compile Package "gen_pkg"
Compile Entity "name_clash"
Compile Architecture "clash" of Entity "name_clash"
Error: COMP96_0419: name_clash.vhd : (22, 22): Ambiguous reference to "CONST". Visible declarations include 'clash.pkg.CONST' and 'clash.pkg.CONST'.
GHDL:
PS C:\Temp> ghdl.exe -a --std=08 "C:\msys64\home\Patrick Lehmann\temp\trickyhead.vhdl"
C:\msys64\home\Patrick Lehmann\temp\trickyhead.vhdl:19:13:warning: declaration of "pkg" hides instantiation package "pkg" [-Whide]
package pkg is new work.gen_pkg generic map( 9 );
^
C:\msys64\home\Patrick Lehmann\temp\trickyhead.vhdl:22:22: no declaration for "const" (due to conflicts)
report to_string(CONST);
^
C:\msys64\mingw64\bin\ghdl.exe: compilation error
So Aldec is reporting a name clash on CONST by including both packages in the process. While GHDL is replacing the pkg instance inside the process scope with a new package.
I cannot find a reference in the LRM to specify which behaviour is correct.
Edited by Richard Head