Andreas Fertig
Read post

From Undefined to Defined: Using std::launder in C++

A deep dive into C++17's std::launder, explaining when and why it's needed to avoid undefined behavior when using placement new. Covers scenarios where the compiler's optimizer can make incorrect assumptions about pointer contents — particularly with const members or type-erased buffers — and shows how std::launder acts as an optimization fence. Also contrasts std::launder with reinterpret_cast, std::bit_cast, and std::start_lifetime_as in a summary table.

    #c++
May 05•5m read time•From andreasfertig.com
Post cover image
Table of contents
When things may breakWhen things get more complicatedstd::launder to the rescue
362 Impressions
Andreas Fertig's image
Andreas Fertig

Andreas Fertig's blog offers insights into C++ development, particularly focusing on the C++ Standar...

35 Followers

•

128 Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard