News for hackers. Stuff that matters.
Re:Why Const Doesn't Make C Code Faster by saagarjha on Monday August 19, 2019 @05:13PM (#20741890)
Yes, I know what std::launder does, and that document contains some of my own thoughts: namely, placement new (the only use I've seen suggested) should automatically launder, and std::launder should just not exist.
Re:Why Const Doesn't Make C Code Faster by gpderetta on Tuesday August 20, 2019 @06:38AM (#20745386)
AFAIK placement new does launder. But both new and launder have no effect on their argument (well, placement new of course constructs an object there), they only 'bless' pointer returned from it. The use case is if you placement new on some byte storage. Now you want to access the object stored there, and of course you do not want to placement new the storage again, nor you have cached the result of the previous placement new (it would be suboptimal), instead you want to get a pointer to T from the storage address itself.
Re:Why Const Doesn't Make C Code Faster by saagarjha on Tuesday August 20, 2019 @01:45PM (#20749730)
> AFAIK placement new does launder. But both new and launder have no effect on their argument (well, placement new of course constructs an object there), they only 'bless' pointer returned from it.

I may be misunderstanding, but this seems to directly contradict what the linked paper says:

> Note that std::launder() does not “white wash” the pointer for any further usage.

> The obvious question is, why don’t we simply fix the current memory model so that using data where placement new was called for implicitly always does launder?

Re:Why Const Doesn't Make C Code Faster by gpderetta on Tuesday August 20, 2019 @07:20PM (#20753239)
Because the placement new might have been called in a other translation unit for example so the compiler can't track the it.
Re:Why Const Doesn't Make C Code Faster by gpderetta on Tuesday August 27, 2019 @09:38AM (#20809438)
> I may be misunderstanding, but this seems to directly contradict what the linked paper says: >> Note that std::launder() does not “white wash” the pointer for any further usage.

no, it is consistent. Launder does not white wash its parameter, only its return pointer and any pointer returned by it. Same for placement new.