Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing reinterpret_cast UB with start_lifetime_as in C++23 #426

Open
ariddl opened this issue Aug 18, 2024 · 4 comments
Open

Fixing reinterpret_cast UB with start_lifetime_as in C++23 #426

ariddl opened this issue Aug 18, 2024 · 4 comments

Comments

@ariddl
Copy link

ariddl commented Aug 18, 2024

Channel

C++ Weekly

Topics

  1. Quick review of UB from reinterpret_cast
  2. Quick review of std::bit_cast and any of its limitations
  3. (New in C++23) start_life_timetime_as and start_lifetime_as_array

Length

Longer form (~10 min)

Note

I know there is an existing suggestion here from 2022 on this C++23 feature, but I really wanted to bump it. Pointer aliasing continues to be a very common source of UB from my experience inside and outside the workforce, and I really want more attention on this topic since a true solution is coming in C++23.

@lefticus
Copy link
Owner

I have been literally waiting years to do this episode - no compiler supports start_lifetime_as yet, so it effectively doesn't exist!

@Dharmesh946
Copy link

indeed.
Yet they are lot's of expectation about type punning and lots of wrong info about what is possible or not with C++. start_life_time_as only covers a special case.
I think that they are many episode suggestions about that and there is already an episode about reinterpret_cast. But there is more to that: implicit_lifetime objects, allocation/deallocation in presence of type-punning, std::launder correct usage (and what it cannot do also),...

@LB--
Copy link

LB-- commented Sep 9, 2024

@Dharmesh946 you might be interested in this video: A Deep Dive Into C++ Object Lifetimes - Jonathan Müller - C++Now 2024

@Dharmesh946
Copy link

@lb thanks a lot, I'll have a look at it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants