La risposta che ti ho dato è identica al workaround che hai postato.
Amaro C++, il gusto pieno dell'undefined behavior.
Regole del Forum