Essentially there is special wording all around the c++17 draft standard that gives std::byte
the same properties with regard to aliasing as char
and unsigned char
.
To give you an example, the the C++17 standard, [basic.lval] p8 states:
If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined.
- […]
- a
char
,unsigned char
, orstd::byte type
.
Essentially, anywhere that char
gets special treatment in the standard, the same is given to std::byte
. As far as accessing memory is concerned, it seems irrelevant that it is defined as an enum class
or what it’s underlying type is.
However, enumeration types used to be under-specified until CWG 2590. Underlying type should determine size and alignment requirements of an enum, which added the wording:
An enumeration has the same size, value representation, and alignment requirements as its underlying type.
Furthermore, each value of an enumeration has the same representation as the corresponding value of the underlying type.
– [dcl.enum] p9
You can assume that this defect report applies to C++17 as well.