diff options
author | johannst <johannst@users.noreply.github.com> | 2023-08-01 21:36:44 +0000 |
---|---|---|
committer | johannst <johannst@users.noreply.github.com> | 2023-08-01 21:36:44 +0000 |
commit | 928b2fa4af916a5f75d1269620914f7bb4225e6e (patch) | |
tree | a4f55d013543b79d3acc84c39238ae9ce9cbff9f /development/c++ | |
parent | 75983cdedc08916cc08875cb8b543ecf6befb35f (diff) | |
download | notes-928b2fa4af916a5f75d1269620914f7bb4225e6e.tar.gz notes-928b2fa4af916a5f75d1269620914f7bb4225e6e.zip |
deploy: e6cab7826a010b34670e825650167b0d975d5819
Diffstat (limited to 'development/c++')
-rw-r--r-- | development/c++/fwd-perfect.cc | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/development/c++/fwd-perfect.cc b/development/c++/fwd-perfect.cc index 2fafc3e..15bf2b4 100644 --- a/development/c++/fwd-perfect.cc +++ b/development/c++/fwd-perfect.cc @@ -54,7 +54,11 @@ struct option { constexpr T& value() { assert(m_has_val); - return *reinterpret_cast<T*>(m_val); + // Placement new starts a new lifetime, launder pointer returned to the + // aligned storage. + // + // [1] https://en.cppreference.com/w/cpp/utility/launder + return *__builtin_launder(reinterpret_cast<T*>(m_val)); } private: |