
On Thu, Dec 17, 2009 at 12:19 PM, Dean Michael Berris <mikhailberis@gmail.com> wrote:
On Fri, Dec 18, 2009 at 3:10 AM, Emil Dotchevski <emildotchevski@gmail.com> wrote:
On Thu, Dec 17, 2009 at 10:07 AM, Giovanni Piero Deretta <gpderetta@gmail.com> wrote:
... but the dynamic type of the internal buffer of boost::optional has been changed via placement new, so (modulo compiler bugs) it should be safe: at any time the buffer has a specific type (when initialized) or no type at all (it is just a bunch of memory). Boost optional only dereferences the buffer when it has been initialized, and always with the same type used for placement new. Of course this is hard (impossible?) to prove statically and gcc warns even if it should be perfectly safe .
We had a discussion about warnings some time ago, I think this is an excellent example of a warning that warns about something important yet it is completely useless.
I don't understand why it's "completely useless" when in cases where they are done wrong it can cause a runtime crash.
Because the information the compiler gives you in this case is "you have used reinterpret_cast, your program *might* violate the C++ standard" but it can't know if you're violating it or not. So what it really says is "warning, you're using reinterpret_cast" which is useless because you know that you are using reinterpret_cast.
To someone who doesn't know the semantics of reinterpret_cast, perhaps the warning has some value, but for the rest of us what it really says is "Warning! You have used reinterpret_cast!"
Sure, but isn't reinterpret_cast considered bad because of the fact that there is no standard implementation of it?
I'm not sure what you mean. There is a standard implementation of reinterpret_cast. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode