Fix C.183.

This commit is contained in:
Gabriel Dos Reis 2017-05-01 11:05:32 -07:00
parent 918a5695c7
commit f9f3422ac5

View File

@ -8024,11 +8024,11 @@ If you wanted to see the bytes of an `int`, use a (named) cast:
void if_you_must_pun(int& x)
{
auto p = reinterpret_cast<unsigned char*>(&x);
cout << p[0] << '\n'; // undefined behavior
cout << p[0] << '\n'; // OK; better
// ...
}
Accessing the result of an `reinterpret_cast` to a different type from the objects declared type is still undefined behavior,
Accessing the result of an `reinterpret_cast` to a different type from the objects declared type is defined behavior (even though `reinterpret_cast` is discouraged),
but at least we can see that something tricky is going on.
##### Note
@ -8036,6 +8036,8 @@ but at least we can see that something tricky is going on.
Unfortunately, `union`s are commonly used for type punning.
We don't consider "sometimes, it works as expected" a strong argument.
C++17 introduced a distinct type `std::byte` to facilitate operations on raw object representation. Use that type instead of `unsigned char` or `char` for these operations.
##### Enforcement
???