Ancestors

Toot

Written by Jérôme Humbert on 2024-05-30 at 13:47

Pretty nasty looking footgun in the C++ exception API : std::exception(const std::string&) references the buffer of the string by raw pointer, but by C++ rules as I understand the stack gets unwound just after the catch() args are initialized, so would destroy any stack-allocated std::string used in throwing the exception. Am I missing something here? 🤔

=> More informations about this toot | More toots from djee@mastodon.gamedev.place

Descendants

Written by aeva on 2024-05-30 at 16:59

@djee It's fine if the string object isn't stack allocated. If you pass a stack allocated string, it may produce the illusion of working correctly if the stack unwinds far enough and any heap allocated part isn't reclaimed before it's used, but that's obviously a bad idea.

=> More informations about this toot | More toots from aeva@mastodon.gamedev.place

Written by Jérôme Humbert on 2024-05-30 at 17:37

@aeva Yes that's my analysis. Which means the API is terrible, and I found 4 bugs. The API should never assume that the string is not stack allocated, especially as the expected lifetime is so poorly documented in the spec.

=> More informations about this toot | More toots from djee@mastodon.gamedev.place

Written by aeva on 2024-05-30 at 17:41

@djee fwiw I've heard folks are working on a replacement that might get standardized. C++ exceptions are bad.

=> More informations about this toot | More toots from aeva@mastodon.gamedev.place

Written by Jérôme Humbert on 2024-05-30 at 18:59

@aeva Yes they're not great. But that constructor on runtime_error was really unexpected. I'm surprised they vetted that footgun.

=> More informations about this toot | More toots from djee@mastodon.gamedev.place

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/112530349918148392
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
317.066579 milliseconds
Gemini-to-HTML Time
0.774597 milliseconds

This content has been proxied by September (ba2dc).