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
@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
@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
@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
@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 This content has been proxied by September (ba2dc).Proxy Information
text/gemini