From 928b2fa4af916a5f75d1269620914f7bb4225e6e Mon Sep 17 00:00:00 2001 From: johannst Date: Tue, 1 Aug 2023 21:36:44 +0000 Subject: deploy: e6cab7826a010b34670e825650167b0d975d5819 --- development/c++.html | 6 +++++- development/c++/fwd-perfect.cc | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'development') diff --git a/development/c++.html b/development/c++.html index 6b4fb47..94cc7fd 100644 --- a/development/c++.html +++ b/development/c++.html @@ -748,7 +748,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: 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(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(m_val)); } private: -- cgit v1.2.3