libstdc++ implements the storage type through a variadic union and I think that might be the only solution for variant storage that guarantees no undefined behaviour. But then again, I can't see how one would obtain two references to the variant storage of different types without their code being broken anyway (the highest risk would probably be some code inside this library being miscompiled because of strict aliasing optimizations). So maybe it's enough to disable this warning (which is what I am currently doing myself)?
After upgrading to GCC 7, when compiling at
-O2
I now get a warning about a strict aliasing violation:libstdc++ implements the storage type through a variadic union and I think that might be the only solution for variant storage that guarantees no undefined behaviour. But then again, I can't see how one would obtain two references to the variant storage of different types without their code being broken anyway (the highest risk would probably be some code inside this library being miscompiled because of strict aliasing optimizations). So maybe it's enough to disable this warning (which is what I am currently doing myself)?