r/cpp • u/SkoomaDentist Antimodern C++, Embedded, Audio • Aug 05 '25
Why still no start_lifetime_as?
C++ has desperately needed a standard UB-free way to tell the compiler that "*ptr is from this moment on valid data of type X, deal with it" for decades. C++23 start_lifetime_as promises to do exactly that except apparently no compiler supports it even two years after C++23 was finalized. What's going on here? Why is it apparently so low priority? Surely it can't be a massive undertaking like modules (which require build system coordination and all that)?
105
Upvotes
View all comments
Show parent comment
1
u/SoerenNissen Aug 07 '25 edited Aug 07 '25
https://en.cppreference.com/w/cpp/language/pointer.html
... ok let me see if I can understand "
int A::* p = 0;" correctly in the light of that.It allows you to replace this:
With something substantially more type safe:
I understand it such that
pis an integer pointer but not any abitrary integer pointer. If I set it, it must specifically point to an integer stored inside anA. Now,Adoesn't have anyintmembers but that's OK because it's a nullptrHowever, if we could set it to something, it wouldn't actually point to "an
int," - it contains only the offset down to thatint, such that must supply the object along with the pointer to get a validint.And the reason it works with inheritance is that the type is specifically associated with
A::, such that if I use it with a subclass ofA, the additional offset (if any) is known by the compiler.Does any of that sound off?