Skip to content

Commit d4224eb

Browse files
committed
C.183: Mention bit_cast as a C++20+ solution
1 parent 2a64d42 commit d4224eb

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

CppCoreGuidelines.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9032,7 +9032,9 @@ but at least we can see that something tricky is going on.)
90329032
Unfortunately, `union`s are commonly used for type punning.
90339033
We don't consider "sometimes, it works as expected" a conclusive argument.
90349034

9035-
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.
9035+
Modern C++ introduced `std::byte` (C++17) and `std::bit_cast` (C++20) to facilitate operations on raw object representations.
9036+
Use `reinterpret_cast` along with `std::byte` instead of `unsigned char` or `char` for these operations.
9037+
For `std::bit_cast`, if there is no value of the return type (the `To` type) that can represent the value produced, the behavior is undefined.
90369038

90379039
##### Enforcement
90389040

0 commit comments

Comments
 (0)