nvc
nvc copied to clipboard
Type conversion subtype constraint check not performed
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Top_PhysicalTest_Simple is
end entity;
architecture top of Top_PhysicalTest_Simple is
constant int_1 : INTEGER := natural(0.5);
constant int_2 : INTEGER := natural(-1.5);
begin
assert FALSE report "16 - int_1 (natural(0.5)): " & INTEGER'image(int_1) severity note;
assert FALSE report "17 - int_2 (natural(-1.5)): " & INTEGER'image(int_2) severity note;
end;
And when run:
nvc -r top_physicaltest_simple
** Note: 0ms+0: Assertion Note: 17 - int_2 (natural(-1.5)): -1
Process :top_physicaltest_simple:line_12
File top_phystest_simple.vhdl, Line 12
** Note: 0ms+0: Assertion Note: 16 - int_1 (natural(0.5)): 0
Process :top_physicaltest_simple:line_11
File top_phystest_simple.vhdl, Line 11
The declaration of constant_int2 should incur an elaboration time error.
See IEEE Std-1076-1993/2008 7.3.5/9.3.6 Type conversions:
If the type mark denotes a subtype, conversion consists of conversion to the target type followed by a check that the result of the conversion belongs to the subtype. ... In the case of conversions between numeric types, it is an error if the result of the conversion fails to satisfy a constraint imposed by the type mark.
This now fails at analysis time:
$ ./bin/nvc -a /tmp/test.vhd
** Error: type conversion argument -1.5 out of bounds 0 to 2147483647
File /tmp/test.vhd, Line 9
constant int_2 : INTEGER := natural(-1.5);
^^^^