std::byte 指针是否具有与 char* 相同的别名含义?

Has a std::byte pointer the same aliasing implications as char*?

C++(和 C)严格的别名规则包括 char*unsigned char* 可以别名任何其他指针。

据我所知,uint8_t* 没有类似的规则。

因此我的问题是:std::byte 指针的别名规则是什么?

C++ 参考目前只有 specifies:

Like the character types (char, unsigned char, signed char) it can be used to access raw memory occupied by other objects (object representation), but unlike those types, it is not a character type and is not an arithmetic type.

来自当前标准草案 ([basic.types]/2):

For any object (other than a base-class subobject) of trivially copyable type T, whether or not the object holds a valid value of type T, the underlying bytes ([intro.memory]) making up the object can be copied into an array of char, unsigned char, or std​::​byte ([cstddef.syn]).43 If the content of that array is copied back into the object, the object shall subsequently hold its original value.

所以是的,相同的别名规则适用于这三种类型,正如 cppreference 总结的那样。

提及 ([basic.lval]/8.8) 也可能很有价值:

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, or std​::​byte type.