From 72b235041b3a3af2f82c4c5105ca0fc271a8c61b Mon Sep 17 00:00:00 2001 From: Herb Sutter Date: Thu, 30 Sep 2021 11:43:57 -0700 Subject: [PATCH] Update C.183 to use `std::byte`, closes #1823 --- CppCoreGuidelines.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 030ce7c..33bda3f 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -8810,12 +8810,12 @@ 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(&x); + auto p = reinterpret_cast(&x); cout << p[0] << '\n'; // OK; better // ... } -Accessing the result of a `reinterpret_cast` to a type different from the object's declared type is defined behavior. (Using `reinterpret_cast` is discouraged, +Accessing the result of a `reinterpret_cast` from the object's declared type to `char*`, `unsigned char*`, or `std::byte*` is defined behavior. (Using `reinterpret_cast` is discouraged, but at least we can see that something tricky is going on.) ##### Note