Cute C++ trick of the day: a few odd quirks of C++ allow you to create a registry of atomically-modified global variables that spookily jump over unreachable code: godbolt.org/z/v75zdG4fb (Idea: @zygoloid. Yes, this is horrifying. Advanced version here: godbolt.org/z/vns6n5aa3)

Nov 8, 2021 路 3:00 PM UTC

But is _ really necessary? What about just static std::string stored; stored = v; throw Success{}; // unreachable return []{ return stored; }
That's a race in concurrent code 馃榾
Watching you talk about this at Pure Virtual C++ 2022! This is amazing... please, please, keep these nuggets of joy coming our way! Simply, amazing!
1
so how does it work? how does it jump over the unreachable part ?
1
1
馃槶馃槶馃槶馃槶
Nice! Does it still work if we remove static from static int _? I think it does, but I'm not quite sure...
This may be a silly q (since I don't understand the code yet), but why doesn't the "return stored" lambda get optimized out due to being after an unreachable statement? Is jumping past the unreachable defined behavior despite violating the unreachable assumption?