Thanks. Is this “It is possible for an enum to have a value that is not in the value set.” somewhere explicitly mentioned in the 1800-2012 standard? Do you know if the current versions of Modelsim and NCsim honor the standard in this aspect? I am asking because we just had an issue where the simulator set the initial default value of the enum not to 'x but to the leftmost constant in the enums value set.
If the enums value is not in the value set, doesn’t this change the type of the enum, since the value set defines the type?
For example, the LRM says, “Casting can be used to perform an assignment of a different data type, or an out-of-range value, to an enumerated type.”
No, this does not change the data type. The value set does not define the base data type of the enum, only a set of names and associated values that are legal assignment values in simple assignments.
This is what happens when you have language design by committee.
Originally, enumerated were strongly typed. They could have only the values defined by their labels, and their initial value was the first label. But then people (most likely hardware engineers) wanted to manipulate individual bits of the enum. But trying to do type checking while assigning to a bit-select of an enum variable would have been very difficult. They also wanted to have their enum variables come up in the X state without having to explicitly specify that. So the default initial value was changed to be the base data type default.
So unless you have linting tools, it is now difficult to rely on the strong typing of enums in SystemVerilog. Some tools now even ignore the remaining assignment restrictions.
It’s possible that vendors have not kept up with all the changes, you will have check with each one of them.
Yes, this is exactly the problem. Enums violate strong typing in the 1800-2012 standard. To make it worse, the tools report violations inconsistently:
enum int {a=3} ea;
enum int {b=6} eb;
initial eb=ea;
produces the following warning:
ncvlog: *W,ENUMERR (test.sv,7|7): This assignment is a violation of SystemVerilog strong typing rules for enumeration datatypes.
But at initialization, both enums get assigned 0 as the default value of their base type, without any warning.
So similar violations of typing rules get reported differently.