Reputation: 901
I have a class defined as follows
struct X {
X() : data() {}
int data;
enum class Zzz : int { zero, one, two };
Zzz zzz;
};
...
X xval;
What is the value of xval.zzz - is undefined or X::Zzz.zero ? I know it will be undefined for regular enums and I am wondering whether typed enums behave differently.
Upvotes: 4
Views: 2352
Reputation: 234665
It's uninitialised.
Since the backing type is an int
and that can contain a trap representation, the reading of xval.zzz
prior to initialisation is undefined. (Out of interest, if the backing type was a char
, unsigned char
, or signed char
, then the behaviour would be merely implementation defined.)
Upvotes: 4